iPhone UISearchBar View 没有立即更新?

标签 iphone objective-c uisearchbar uisearchdisplaycontroller

我目前有一个 UISearchBar 和 UIDisplayController 在我的 RootViewController 中定义为:

- (void)viewDidLoad {
    [super viewDidLoad];

    //Add the search bar
    aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
    [aSearchBar sizeToFit];
    aSearchBar.delegate = self;
    aSearchBar.placeholder = @"Search YouTube...";

    self.tableView.tableHeaderView = aSearchBar;

    searchDC = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];

    [self performSelector:@selector(setSearchDisplayController:) withObject:searchDC];

    searchDC.delegate = self;
    searchDC.searchResultsDataSource = self;
    searchDC.searchResultsDelegate = self;

    [aSearchBar release];
    [searchDC release];

}

当触发搜索按钮时,将执行此事件以运行 API 调用:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [videoList removeAllObjects];
    if (searchBar.text.length > 0) {
        NSString *searchCriteria = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@"+"];

        YTJAppDelegate *appDelegate=(YTJAppDelegate*)[[UIApplication sharedApplication] delegate];
        [appDelegate searchWithCriteria:searchCriteria];

    }       
}

数据获取正确。然而。只有当我在搜索中点击“取消”按钮时,它才会变得可见。

如何在数据源更新/搜索按钮被点击时正确更新 View ?我需要实现一个特殊的 SearchDelegate 方法吗?

最佳答案

关联 TableView 的代码可能会有帮助,但我猜你不会在搜索完成后调用 [self.tableView reloadData]

关于iPhone UISearchBar View 没有立即更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3639293/

相关文章:

ios - 呈现 UISearchController 与状态栏重叠

iphone - 如何使 subview 显示在键盘顶部?

iphone - 基于视觉的增强现实 Objective-C 库

iphone - 调整应用程式内音量

objective-c - 你可以手动实现 Cocoa 绑定(bind)吗?

ios - 如何在 UIAlertController 上添加动态按钮?

ios - UISearchBar 范围栏位置?

ios - 如何将 UISearchController 搜索栏设置为不是 tableHeaderView 或 navigationItem.titleview 的 View ?

ios - 使用IOS中的CLLocation获取用户当前位置

objective-c - 不了解 UIActivityIndi​​catorView 如何与 NSTimer 一起工作