Mik*_*e V 2 exc-bad-access uisearchbar ios ios7
//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
}
Run Code Online (Sandbox Code Playgroud)
viewDidLoad仅在iOS 7 Gold Master和更新版本上调用时,才会显示EXC_BAD_ACCESS .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中失败.
尝试以下代码来自此博客:
-(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];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1487 次 |
| 最近记录: |