2012-06-07 78 views

回答

0

創建一個從TTSearchDisplayController衍生一個新的顯示控制器XXSearchDisplayController,在XXSearchDisplayController.m

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller  
shouldReloadTableForSearchString:(NSString *)searchString { 
return NO; 
} 

這將禁用自動搜索。在此之後,去從TTTableViewController派生類,說XXProductsTableViewController

@implementation XXProductsTableViewController 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     UISearchBar* searchBar = [[UISearchBar alloc] init]; 
     searchBar.delegate = self; 
     _searchController = [[XXSearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; 
    } 
    return self; 
} 

#pragama mark - UISearchBarDelegate 
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { 
    [self.searchViewController.dataSource search:searchBar.text]; 
} 
@end 

上面的代碼將做到一旦用戶點擊搜索「搜索」按鈕