标签:atom ini ram board key oid cto 解决 sea
最近一个项目用到了很多搜索 踩了一大波坑 还要继续踩下去
直接上代码了
<UISearchControllerDelegate,UISearchResultsUpdating> //声明 @property (nonatomic,retain) UISearchController *searchController; - (void)createUI{ self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil]; self.searchController.delegate= self; self.searchController.searchResultsUpdater = self; self.searchController.searchBar.barTintColor = BHBackColor; self.searchController.searchBar.placeholder= @"车牌号"; self.searchController.searchBar.searchBarStyle =UISearchBarStyleMinimal; // //提前在搜索框内加入搜索词 // self.searchController.searchBar.text = @"xxxx"; self.searchController.searchBar.tintColor = BHNoticeColor; //搜索时,背景变暗色 self.searchController.dimsBackgroundDuringPresentation = NO; //搜索时,背景变模糊 // self.searchController.obscuresBackgroundDuringPresentation = NO; //点击搜索的时候,是否隐藏导航栏 // self.searchController.hidesNavigationBarDuringPresentation = NO; self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0); self.definesPresentationContext = YES; self.searchController.hidesNavigationBarDuringPresentation = NO; [self.searchController.searchBar setContentMode:UIViewContentModeLeft]; self.navigationItem.titleView =self.searchController.searchBar; UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.rightBarButtonItem = rightBarItem; [self.view addSubview:self.searchTableView]; } //谓词搜索过滤 -(void)updateSearchResultsForSearchController:(UISearchController *)searchController { NSLog(@"搜索"); NSString *searchString = [self.searchController.searchBar text]; //下面处理数据 怎么处理的都可以 这个方法是 searchbar 内容改变一次就调用一次 }
想要在跳转页面的时候键盘直接弹出来
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self performSelector:@selector(showKeyboard) withObject:nil afterDelay:0]; } - (void)showKeyboard { [self.searchController.searchBar becomeFirstResponder]; }
如果
self.searchController.hidesNavigationBarDuringPresentation = YES; //默认是YES
不要在
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{ //不要加 self.edgesForExtendedLayout = UIRectEdgeNone; }
否则会在返回的时候上移 44个像素
连接涉及到的坑
iOS双击Home键进入switcher任务管理切屏退出进入闪屏的解决办法
测试结果 第一种和第二种不可用 如果有加搜索的话取消按钮也会变成透明的 第三种 [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(1000, 1000) forBarMetrics:UIBarMetricsDefault];
其他待更新......
标签:atom ini ram board key oid cto 解决 sea
原文地址:http://www.cnblogs.com/xuaninitial/p/6729874.html