ios - 搜索栏 IOS 8 - 显示两个搜索栏

标签 ios xcode uisearchbar

正在使用 UISearchController IOS 8,使用 ResultUpDating Delegate

代码如下

- (void)viewDidLoad {

    [super viewDidLoad];

    self.products = [Product allProducts];

    // Create a mutable array to contain products for the search results table.
    self.searchResults = [NSMutableArray arrayWithCapacity:[self.products count]];

    // The table view controller is in a nav controller, and so the containing nav controller is the 'search results controller'
    UINavigationController *searchResultsController = [[self storyboard] instantiateViewControllerWithIdentifier:@"TableSearchResultsNavController"];

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

    self.searchController.searchResultsUpdater = self;

    self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);

    self.tableView.tableHeaderView = self.searchController.searchBar;

#if ENABLE_SCOPE_BUTTONS

    NSMutableArray *scopeButtonTitles = [[NSMutableArray alloc] init];
    [scopeButtonTitles addObject:NSLocalizedString(@"All", @"Search display controller All button.")];

    for (NSString *deviceType in [Product deviceTypeNames]) {
        NSString *displayName = [Product displayNameForType:deviceType];
        [scopeButtonTitles addObject:displayName];
    }

    self.searchController.searchBar.scopeButtonTitles = scopeButtonTitles;
    self.searchController.searchBar.delegate = self;

#endif

    self.definesPresentationContext = YES;

}

委托(delegate)方法是

-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
    // Set searchString equal to what's typed into the searchbar
    NSString *searchString = self.searchController.searchBar.text;
    //NSLog(@"o");

    [self fetchByPatientName:searchString];



}
- (void)fetchByPatientName:(NSString *)patientName
{

//Code TO Fetch

// Code To Update Table

}

我的 Storyboard [enter image description here ][1

运行后我得到两个搜索栏,我正在寻找如何解决它

非常感谢您的帮助。

enter image description here

最佳答案

删除以下内容应该可以解决问题

 self.tableView.tableHeaderView = self.searchController.searchBar

关于ios - 搜索栏 IOS 8 - 显示两个搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34586910/

相关文章:

ios - 将 UIButton 放置在具有约束的 UIScrollView 底部

ios - HTML5 视频时长问题

ios - 从用户通知中打开设置URL?

iphone - Xcode 4,使用断点记录或 po 对象

json - 快速搜索 JSON

android - 在 Microsoft Azure VDI 中设置用于 iOS 开发的 Mac OS 环境

xcode - 以编程方式快速将 NSClickGestureRecognizer 添加到 NSButton

ios - 从 UICollectionViewCell 执行 Segue

ios - 如何隐藏/禁用 UISearchBar 范围栏

ios - 试图做一个复合谓词。不工作。