I have been struggling with change of text on Cancel button in iOS7.
In iOS6 I have no problem -- the text is changed. But in iOS7 it has no effect and I am stuck with "cancel".
But finally I found the code below which changes the default "cancel" text in iOS7.
The problem now is that running in iOS6 the app crashes when opening the search bar.
Does anybody know why and how to fix this to work both on iOS7 and iOS6? This is the error message.
2013-11-10 16:58:38.048 Testapp[45017:907] -[__NSCFConstantString setTitle:forState:]: unrecognized selector sent to instance 0x11dfc 2013-11-10 16:58:38.050 Testapp[45017:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString setTitle:forState:]: unrecognized selector sent to instance 0x11dfc'
And the main.m
int retVal = UIApplicationMain(argc, argv, nil, nil);
gets a Thread 1:signal SIGABRT
The code is as below.
-(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) {
[cancelButton setTitle:@"Testing" forState:UIControlStateNormal];
}
}