自定义UISearchDisplayController的“No Results“标签和”Cancel“按钮

本文转载至 http://www.cnblogs.com/pengyingh/articles/2350154.html

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {

UISearchBar *searchBar = self.searchDisplayController.searchBar;

[searchBar setShowsCancelButton:YES animated:YES];

for(UIView *subView in searchBar.subviews){

if([subView isKindOfClass:UIButton.class]){

[(UIButton*)subView setTitle:@"取消" forState:UIControlStateNormal];

}

}

}

No Results:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString

{

[self filterContentForSearchText:searchString];

if ([filteredListPinYin count] == 0) {

UITableView *tableView1 = self.searchDisplayController.searchResultsTableView;

for( UIView *subview in tableView1.subviews ) {

if( [subview class] == [UILabel class] ) {

UILabel *lbl = (UILabel*)subview; // sv changed to subview.

lbl.text = @”没有结果”;

}

}

}

// Return YES to cause the search result table view to be reloaded.

return YES;

}

 

 
 
posted @ 2014-11-05 15:21  天牛  阅读(181)  评论(0编辑  收藏  举报