我現在有一個UISearchBar和UIDisplayController在我的RootViewController的定義爲:iPhone UISearchBar視圖不立即更新?
- (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方法嗎?
是否有一個特定的方法,我應該調用它? – unicornherder 2010-09-03 20:43:16
可能在搜索完成後 – 2010-09-03 20:44:04
當Array對象更改爲更新tableView時,我當前有一個「觀察者」檢測。 有沒有一種方法來編程激發'取消按鈕'事件? – unicornherder 2010-09-03 20:57:09