我正在尝试以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]; …Run Code Online (Sandbox Code Playgroud) 我正在尝试重新创建这个UISearchBar(如表搜索示例代码中所示):
替代文字http://img168.imageshack.us/img168/6378/43558113.png
我见过的所有这些例子都涉及使用xib,但我需要以编程方式进行.问题是改变色调颜色也会改变取消按钮的色调:
替代文字http://img243.imageshack.us/img243/1375/screenshot20100527at944.png
有任何想法吗?
我正在构建一个使用新UISearchController的iOS 8应用程序.在与搜索控制器相关的表视图中,我使用区段索引让用户从表的一个部分快速跳转到下一个部分.它工作正常,但部分索引与表/搜索控制器上的搜索栏重叠.有没有人遇到过这个问题,如果有的话,你是怎么解决的?以下是我正在初始化搜索控制器的方法:
self.resultsTableController = [self.storyboard instantiateViewControllerWithIdentifier:[SelectSpecialtySearchResultsTVC storyboardId]];
UINavigationController *searchResultsNavController = [[UINavigationController alloc]initWithRootViewController:self.resultsTableController];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsNavController];
self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.barTintColor = [UIColor colorWithHexString:kColorGrayLight];
self.searchController.searchBar.translucent = NO;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, [self.view bounds].size.width, 44.0);
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
//present the search display controller within the confines of this class's table view
self.definesPresentationContext = YES;
// we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables
self.resultsTableController.tableView.delegate = self; …Run Code Online (Sandbox Code Playgroud)