gpt4 book ai didi

ios - EXC_BAD_ACCESS 与 UIBarButtonItem appearanceWhenContainedIn 在 iOS 7

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:02:44 24 4
gpt4 key购买 nike

//Set all cancel buttons in search bars to "Done"
id searchBarButton = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[searchBarButton setTitle:@"Done"];
} else {
//Can't do anything here or i get EXC_BAD_ACCESS
}

这在 viewDidLoad 中调用时给出 EXC_BAD_ACCESS仅适用于 iOS 7 Gold Master 及更高版本。 iOS 7 beta 6 及更早版本都可以。

在 iOS 7 中是否有不同的方法来执行此操作?

NSLog("%@", searchBarButton)在 iOS7 上的结果是:

2013-10-01 16:14:25.972 MP Staging[12293:a0b] <_UIBarItemAppearance:0x1aaf72d0> <Customizable class: UIBarButtonItem> when contained in (
UISearchBar
) with invocations (null)>

和这个在 iOS 6 上

<_UIBarItemAppearance: 0x1c671aa0>

最佳答案

setTitle 在 iOS7 中会失败。

尝试以下来自 this 的代码博客:

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
self.searchDisplayController.searchBar.showsCancelButton = YES;
UIButton *cancelButton;
UIView *topView = self.searchDisplayController.searchBar.subviews[0];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
}
}
if (cancelButton) {
//Set the new title of the cancel button
[cancelButton setTitle:@"Annuller" forState:UIControlStateNormal];
}
}

关于ios - EXC_BAD_ACCESS 与 UIBarButtonItem appearanceWhenContainedIn 在 iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19124516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com