Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.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 UISearchDisplayController不';t在iPad上显示结果tableview_Ios_Objective C_Ipad_Swift_Uisearchdisplaycontroller - Fatal编程技术网

Ios UISearchDisplayController不';t在iPad上显示结果tableview

Ios UISearchDisplayController不';t在iPad上显示结果tableview,ios,objective-c,ipad,swift,uisearchdisplaycontroller,Ios,Objective C,Ipad,Swift,Uisearchdisplaycontroller,我想在自定义UIViewController和MKMapView中使用UISearchDisplayController 我在导航栏中显示UISearchBar 所有这些都可以在iPhone上运行,但在iPad上,即使在popover中,也不会显示结果的TableView。。。我只想显示这个tableview (所有代理都已正确初始化) 通过调试,我知道TableView存在(searchDisplayController中有一个地址) 编辑: 除了在导航栏中插入搜索栏外,我在Interface

我想在自定义UIViewController和MKMapView中使用UISearchDisplayController

我在导航栏中显示UISearchBar

所有这些都可以在iPhone上运行,但在iPad上,即使在popover中,也不会显示结果的TableView。。。我只想显示这个tableview

(所有代理都已正确初始化)

通过调试,我知道TableView存在(searchDisplayController中有一个地址)

编辑:

除了在导航栏中插入搜索栏外,我在Interface Builder中设置了所有内容。我只是通过编程实现的:

self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
我不明白,为什么在iPhone中,tableView是显示的而不是iPad

编辑2:

如果我删除导航栏(上面引用的最后一行代码)中的插入项,则会显示tableView,但它是全屏显示,而不是弹出窗口

最终编辑:

在没有解决方案的情况下,我尝试了不同的方法:我将我的视图嵌入到SplitView中,在master视图中进行研究,在detailView中嵌入MapView。这是可行的,但看起来和预期的不一样

答案是:

有了swift和iOS 8,我重新构建了我的应用程序,并找到了一个解决方案来做好这项工作

    if let tableView = self.searchDisplayController?.searchResultsTableView {
        tableView.frame = CGRect(x: 0.0, y: 0.0, width: self.view.bounds.width, height: self.view.bounds.height)
        self.view.addSubview(self.blurEffectView!)
    }

我也有同样的问题。部分解决方案是实施

- (void)searchDisplayController:(UISearchDisplayController *)controller  didShowSearchResultsTableView:(UITableView *)tableView
{
    if (OSVersionIsAtLeastiOS7() && IPAD) { // These are custom methods I have in my .pch file
        self.view = controller.searchResultsTableView;
        controller.searchResultsTableView.contentInset = UIEdgeInsetsZero;
    }
}
在此处找到此解决方案:


不幸的是,还有一个小问题-当用户开始在搜索框中键入时,键盘在键入第一个字符后(对我来说)会被关闭。

@Jeremy谢谢你的回答。我是iOS新手,你的回答帮助我解决了这个问题。下面是一个可能对其他人有帮助的更新

在ViewDidLoad中包含这段代码以保存原始视图的副本

originalView = self.view;
为searchDisplayController添加以下两个委托方法将解决您的问题。 如果将搜索栏放置在NavigationBar中,请使用

UIEdgeInsetsMake(70, 0, 0, 0)
否则请使用
UIEdgeInsetsZero

 - (void)searchDisplayController:(UISearchDisplayController *)controller  didShowSearchResultsTableView:(UITableView *)tableView
    {
        if (OSVersionIsAtLeastiOS7() && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)) { 
            if (([originalView isEqual:self.view])) {
                self.view = controller.searchResultsTableView;
                controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(70, 0, 0, 0);
                [self.searchDisplayController.searchBar becomeFirstResponder]; // This will retain the keyboard after keypress
            }
        }
    }
要随时显示原始视图,请使用
self.view=originalView
在这个委托方法中,我使用了,如果搜索文本为空,则显示原始视图而不是黑屏

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
    if ([searchString isEqualToString:@""]) {
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            self.view = originalView;
        }
    }
    else{
    [self filterContentForSearch:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    }
    return YES;
}

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    originalView.alpha = 0.5f;
}

-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
    originalView.alpha = 1.0f;
}

这为我解决了问题

UISearchBar *searchBar = [UISearchBar new];
searchBar.delegate = self;
[searchBar sizeToFit];

self.navigationItem.titleView = searchBar;

然后不要将ArchBarInnavigationBar显示为YES(是)

这一切是如何设置的?通过代码还是IB?谢谢你的回答。对于iOS 8,我想我将使用新的UISearchController,方式不同:)
UISearchBar *searchBar = [UISearchBar new];
searchBar.delegate = self;
[searchBar sizeToFit];

self.navigationItem.titleView = searchBar;