ios – 未调用UISearchDisplayDelegate方法

ios – 未调用UISearchDisplayDelegate方法,第1张

概述我以编程方式创建一个UISearchBar和UISearchDisplayController.视图控制器是一个UITableViewController. @interface StockTableViewController()< UISearchDisplayDelegate,UISearchBarDelegate>你可以看到下面的代码.但是当我在搜索栏中输入时,不会调用shouldRelo 我以编程方式创建一个UISearchbar和UISearchdisplayController.视图控制器是一个UItableVIEwController. @interface StocktableVIEwController()< UISearchdisplayDelegate,UISearchbarDelegate>你可以看到下面的代码.但是当我在搜索栏中输入时,不会调用shouldReloadtableForSearchString,包括其他UISearchdisplayDelegate方法.

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    self.searchResults = [NSArray array];    UISearchbar *searchbar = [[UISearchbar alloc] init];    searchbar.barStyle = UISearchbarStyleDefault;    searchbar.searchbarStyle = UISearchbarStyleDefault;    searchbar.showsCancelbutton = YES;    searchbar.showsScopebar = NO;    searchbar.delegate = self;    UISearchdisplayController *searchdisplayController = [[UISearchdisplayController alloc] initWithSearchbar:searchbar contentsController:self];    searchdisplayController.delegate = self;    searchdisplayController.searchResultsDataSource = self;    searchdisplayController.searchResultsDelegate = self;    self.tableVIEw.tableheaderVIEw = searchbar;}- (voID)searchdisplayControllerWillBeginSearch:(UISearchdisplayController *)controller{    NSLog(@"searching"); //not showed up in the console}- (BOol)searchdisplayController:(UISearchdisplayController *)controller shouldReloadtableForSearchString:(Nsstring *)searchString{    NSLog(@"%@",searchString); //not showed up in the console    nspredicate *predicate = [nspredicate predicateWithFormat:@"name liKE %@",searchString];    NSArray *results = [Stock MR_findAllSortedBy:@"createdDate" ascending:NO withPredicate:predicate];    if ([results count] > 0) {        self.searchResults = results;        [self.searchdisplayController.searchResultstableVIEw reloadData];    }    return YES;}
解决方法 它不起作用,因为您正在将UISearchdisplayController创建为局部变量,这会导致在vIEwDIDLoad超出范围时将其解除分配.因此,为您的搜索显示控制器创建一个强大的属性,然后它应该正常工作(如果您将属性命名为searchdisplayController,则会遇到命名冲突,因此请将其称为其他内容). 总结

以上是内存溢出为你收集整理的ios – 未调用UISearchDisplayDelegate方法全部内容,希望文章能够帮你解决ios – 未调用UISearchDisplayDelegate方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1008724.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存