所以我在UIPopOverController
里面有一个tableview,我将一个UISearchBar附加到tableview的标题,我让UISearchDisplayController
显示正确的结果。但是,我无法在UIPopoverController
窗口中显示结果。它显示在弹出视图后面DetailView
覆盖屏幕的一半(iPad为SplitViewController
)。如何将结果/ tableview带入弹出窗口视图?我尝试将searchTableView
添加到弹出窗口视图中,但它只是掩盖了原始的tableview。
以下是设置此代码的代码:
//Initialize Popover Controller
UIView *ccPopoverView = [[UIView alloc] init];
UIViewController* popoverTableContent = [[UIViewController alloc] init];
self.ccTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, 400) style:UITableViewStylePlain];
self.ccTableView.dataSource = self;
self.ccTableView.delegate = self;
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320.0, 44.0)];
self.searchDisplayController = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.delegate = self;
searchBar.frame = CGRectMake(0, 0, 0, 38);
self.ccTableView.tableHeaderView = searchBar;
ccPopoverView.backgroundColor = [UIColor blackColor];
//Here is where I tried adding the searchResultsTableView as a subview.
//[ccPopoverView addSubview:self.searchDisplayController.searchResultsTableView];
[ccPopoverView addSubview:self.ccTableView];
popoverTableContent.view = ccPopoverView;
self.popoverTableController.delegate = self;
self.popoverTableController = [[UIPopoverController alloc] initWithContentViewController:popoverTableContent];
[self.popoverTableController setPopoverContentSize:CGSizeMake(320, 440) animated:NO];
谢谢!
答案 0 :(得分:1)
我修复了问题,而不是在初始化搜索栏时添加self
,我需要将popovercontroller作为初始化。