我试图以编程方式创建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