Sort question:
Is there a way to change the "Cancel" button text within a UISearchDi开发者_如何学PythonsplayController
to "Done" or "Close"?
Rationale:
I have a UITableView
that contains a list of options, each option can be checked or unchecked.
I want to enable search through these options, so I've created and added a UISearchDisplayController
.
The user will search for an item, and then perform actions on the items in the search results (i.e. will select/unselect certain items).
Once this is completed the user will then go back to the previous (unsearched) list of options.
The problem is that the only way to dismiss the UISearchDisplayController
is to press the "Cancel" button. However "Cancel" is the wrong word here as the actions conducted while within the Search bar will be stored.
Therefore, is there a way to change the "Cancel" button text to "Done" or "Close"?
I found one way to do this, in the delegate for the searchbar, create an empty animation then after a small duration, change your things on the button, this might be because the cancel button is animated in sometime shortly after the delegate is called, thus you cant grab it and change it before that:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController*)controller {
[UIView
animateWithDuration:0.05 animations:^{} completion:^(BOOL finished){
for (UIView *possibleButton in controller.searchBar.subviews)
{
if ([possibleButton isKindOfClass:[UIButton class]])
{
UIButton *cancelButton = (UIButton*)possibleButton;
//TODO:
// do things with button here...
}
}
}
];
}
精彩评论