Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带UITableView的UISearchController?_Ios_Objective C_Iphone_Uitableview_Uisearchcontroller - Fatal编程技术网

Ios 带UITableView的UISearchController?

Ios 带UITableView的UISearchController?,ios,objective-c,iphone,uitableview,uisearchcontroller,Ios,Objective C,Iphone,Uitableview,Uisearchcontroller,我希望在我的ViewController上创建一个包含UITableView(不是UITableViewController)的UISearchController。我有两个警告和一次撞车,不确定它们是否相关,但我知道我的问题之一是警告 'Imcompatiable pointers types sending UITableView to parameter of type UIViewController.' 显然,这是因为我试图将searchResultsController设置为我的U

我希望在我的ViewController上创建一个包含UITableView(不是UITableViewController)的UISearchController。我有两个警告和一次撞车,不确定它们是否相关,但我知道我的问题之一是警告

'Imcompatiable pointers types sending UITableView to parameter of type UIViewController.'
显然,这是因为我试图将searchResultsController设置为我的UIViewController上的tableView,而不是像这样的UITableViewController:

   self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.myTableView];

如果self.myTableView是UITableView,我将如何着手解决这个问题?我是否必须将tableView转换为UITableViewController才能正常工作?提前感谢。

initWithSearchResultsController方法需要一个视图控制器。根据我的经验,它可以是UIViewController或UITableViewController,只要您想显示过滤(搜索)结果

在您的情况下,我认为,您正试图在保存tableView的同一视图控制器中显示过滤后的结果。因此,下面应该消除您所遇到的错误-

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

但是,您可能还必须将筛选表的数据源设置为self。

如果我了解您的设置,您应该传递self,而不是self.myTableView.Ah,谢谢!现在由于某种原因,当我点击搜索栏时,我的viewcontroller变为黑色(除了导航栏),我得到了这个错误“试图显示不在窗口层次结构中的视图!”不管怎样都无法修复它,显然,如果你打算让视图充当控制器,你必须传入nil而不是self