我試圖以編程方式創建UISearchDisplayController
。我有一個方法應該設置我的搜索控制器,但是當我調用它時,什麼也沒有發生。以編程方式創建UISearchDisplayController
這是我-setupSearch
方法:
- (void)setupSearch {
UISearchBar *myBar;
UISearchDisplayController *myCon;
myBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[myBar sizeToFit];
myCon = [[UISearchDisplayController alloc]
initWithSearchBar:myBar contentsController:self];
[myBar release];
myCon.delegate = self;
myCon.searchResultsDataSource = self;
myCon.searchResultsDelegate = self;
/* Setup scopes */
{
NSMutableArray *scopes;
NSUInteger count, i;
NSString *aScope;
count = SCOPE_COUNT;
scopes = [[NSMutableArray alloc] initWithCapacity:count];
for(i = 0; i < count; i++) {
// I create four scopes here
}
myCon.searchBar.scopeButtonTitles = scopes;
[scopes release];
}
[myCon release];
}
我稱之爲我的子類UITableViewController
的-viewDidLoad
方法上面的方法。不幸的是,當我的表格視圖控制器被顯示在UITabBarController
中時,沒有任何反應。
任何幫助將不勝感激。
從doc中,對contentsController:「這通常是UITableViewController的一個實例。」。通常,不是必需的。 – 2013-05-03 21:56:05
所以,如果你不想使用'UITableViewController',你可以簡單地擁有一個符合UITableViewDataSource和UITableViewDelegate協議的'UIViewController'。 – 2013-10-03 16:02:12
我的問題是'self.searchDisplayController'是'UITableViewController'上的只讀屬性,但是這裏的代碼正在設置它。 – 2014-04-03 00:36:14