<UITableViewDelegate, UITableViewDataSource,BookDetailViewDelegate,UISearchBarDelegate, UISearchDisplayDelegate>这是协议
这是初始化
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 44)];
_searchBar.delegate = self;
[_searchBar setShowsScopeBar:NO];
[_searchBar sizeToFit];
[self.view insertSubview:_searchBar atIndex:3];
都在.m文件中
-
(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{//查询所有 [self filterContentForSearchText:@"" scope:-1];
}
//当文本内容发生改变时候,向表视图数据源发出重新加载消息
(BOOL)searchDisplayController:(UISearchDisplayController )controller shouldReloadTableForSearchString:(NSString )searchString
{
[self filterContentForSearchText:searchString scope:_searchBar.selectedScopeButtonIndex];
//YES情况下表视图可以重新加载
return YES;
}
// 当Scope Bar选择发送变化时候,向表视图数据源发出重新加载消息
(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:_searchBar.text scope:searchOption];
// YES情况下表视图可以重新加载
return YES;
}这三个方法 我输入文字后 断点后发现一个都没执行 为什么啊 第一次写搜索框
delegate 用错了,是 UISearchBar 的 delegate ,不是 UISearchDisplayController 的,你没有用到 SearchDisplayController ,
PS: 下次提问能好好排下版吗……