Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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
iPhone UI搜索栏视图未立即更新?_Iphone_Objective C_Uisearchbar_Uisearchdisplaycontroller - Fatal编程技术网

iPhone UI搜索栏视图未立即更新?

iPhone UI搜索栏视图未立即更新?,iphone,objective-c,uisearchbar,uisearchdisplaycontroller,Iphone,Objective C,Uisearchbar,Uisearchdisplaycontroller,我目前在我的RootViewController中有一个UISearchBar和UIDisplayController定义为: - (void)viewDidLoad { [super viewDidLoad]; //Add the search bar aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero]; [aSearchBar sizeToFit]; aSearchBar.deleg

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

- (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];

    }       
}
正确获取数据。然而。它只有在我点击搜索上的“取消”按钮时才可见


如何在数据源更新/搜索按钮按下时使视图正确更新?是否需要实现特殊的SearchDelegate方法?

关联表视图的代码可能会有所帮助,但我猜您没有调用
[self.tableView reloadData]
搜索完成后

发现解决方案是将searchDisplayController委托和数据源指向它正在实现的表视图:

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

是否有一个特定的方法我应该调用它?可能在搜索完成后,我当前有一个“观察者”检测数组对象何时更改以更新tableView。有没有一种方法可以通过编程触发“取消按钮”事件?