【发布时间】:2013-12-10 06:42:30
【问题描述】:
我有一个带有 UISearchBar 的 mapViewController 和一个带有 UISearchBar 的 listViewController。
它们是不同的控制器并显示在不同的选项卡中,但是当我开始在 UISearchBar 中编辑文本时,我需要在弹出窗口中显示 mapViewController 中的 listViewController。
现在 mapViewController 是 mapViewController 中 UISearchBar 的委托,而 listViewController 是 listViewController 中 UISearchBar 的委托。
所以我在 mapViewController 中实现了委托方法
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (!self.listView) {
self.listView = [self.storyboard instantiateViewControllerWithIdentifier:@"ListViewController"];
self.listView.showInPopover = YES; //HIDES THE UISEARCHBAR IN LISTVIEWCONTROLLER
}
if (!self.listViewPopover) {
self.listViewPopover = [[UIPopoverController alloc] initWithContentViewController:self.listView];
self.listViewPopover.passthroughViews = [NSArray arrayWithObject:searchBar];
self.listViewPopover.delegate = self;
[self.listViewPopover presentPopoverFromRect:searchBar.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
所以现在我需要让 listViewController 成为 mapViewController 上的 UISearchBar 的代表。我该如何解决这个问题?有可能吗?
我尝试添加
searchBar.delegate = self.listView;
在上面的方法中 - 但没有效果。等待您的帮助,谢谢。
【问题讨论】:
标签: ios objective-c delegates popover