100M光纤用什么路由器当交换机之间用光纤连接?

11019人阅读
UIsearchController
开发中,搜索功能使用的频率自然不言而喻, 本文主要讲一些常用的
1.先创建一个搜索框(比较简单的一个搜索框, 系统自带的)
- (void)viewDidLoad {
& & [super
viewDidLoad];
& & // Do any additional setup after loading the view, typically from a nib.
& & self.view.backgroundColor = [UIColor
whiteColor];
& & UISearchBar *myBar = [[UISearchBar
& & myBar.frame =
CGRectMake(0 ,
65, self.view.frame.size.width,
& & [self.view
addSubview:myBar];
显示cancel
& & myBar.showsCancelButton =
看一下效果:
但是系统的搜索框并不是很美观,可以用图片设计,IOS7之前可以用
myBar.backgroundImage=[UIImage resizedImage:@&searchbar_background&];
但是在IOS7之后看不出效果,我们可以给UIimage条件延展,
&@implementation UIImage (Extension) // 根据图片名自动加载适配IOS6和iOS7的图片& &
+ (UIImage *)imageWithName:(NSString *)name& &
{& & & & & & UIImage *image = nil;& & & & & & if (iOS7) { // 处理iOS7的情况& & & & & &
& & & & NSString *newName = [name stringByAppendingString:@&_os7&];& & & & & &
& & & & image = [UIImage imageNamed:newName];& & & & & &
& & }& & & & & & & &
& & if (image == nil) {& & & & & &
& & & & image = [UIImage imageNamed:name];& & & & & &
& & }& & & &
& & return& & & &
// 根据图片名返回一张能自由拉伸的图片& &
+ (UIImage *)resizedImage:(NSString *)name& &
& & UIImage *image = [UIImage imageWithName:name];& & & &
& & return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];& & & &
}如果还是不满意的话就只有自己定义一个搜索栏了, 关于自己封装搜索框,这里就不作说明了下面说一下UISearchController,在IOS8之前都是用UISearchDisplayController, 但是IOS8之后就用UISearchController, UISearchController用起来很方便, 它本身就带有searchBar, 而且自动会模态推到导航栏,下面看一下具体的使用,用UIsearchController实现一个搜索功能由于这个实现功能是点击一个searchbar 之后触发另一个方法A, 方法A实现的创建UIsearchController, 因此,大家可以根据实际情况操作首先在.h里@interface SearchViewController : UIViewController&UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate&// searchCollectionView@property (nonatomic, retain) UICollectionView *searchCollectionV// mySearchController@property (nonatomic, retain) UISearchController *mySearchC// 搜索按钮@property (nonatomic, retain) UIButton *searchB// 存放所有数据的数组@property (nonatomic, retain) NSMutableArray *allDataA// 存放搜索出结果的数组@property (nonatomic, retain) NSMutableArray *searchResultDataA// 搜索控制器@property (nonatomic, retain) UISearchController *searchC// 搜索使用的表示图控制器@property (nonatomic, retain) UITableViewController *searchTVC;// searchBar@property (nonatomic, retain) UISearchBar *// 搜索框输入的东西@property (nonatomic, copy) NSString *inputT接下来.m里1. 创建一个searchBar(其实这个searchBar没有说明大用处)- (void)viewDidLoad {& & [super viewDidLoad];& & // Do any additional setup after loading the view.&& & self.view.backgroundColor = [UIColor brownColor];& & // 创建searchBar& & self.bar=[[UISearchBar alloc]init];& & self.navigationItem.title = @&搜索漫画&;& & //设置bar的frame& & self.bar.frame=CGRectMake(0, 65, 300, 35);& & [self.view addSubview:self.bar];& & self.bar.placeholder = @&漫画名/作者/类型&;& & // 设置键盘类型& & self.bar.keyboardType = UIKeyboardTypeNamePhonePad;& & // searchBar& 代理,记得签协议& & self.bar.delegate = self;}2. 触发方法,创建searchController// searchBar的代理方法,当searchBar的textField开始编辑的时候调用,包含空- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{& & // 创建出搜索使用的表示图控制器& & self.searchTVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];& & _searchTVC.tableView.dataSource = self;& & _searchTVC.tableView.delegate = self;&& &&& && & // 使用表示图控制器创建出搜索控制器& & self.searchController = [[UISearchController alloc] initWithSearchResultsController:_searchTVC];&& && & // 搜索框检测代理& & //(这个需要遵守的协议是 &UISearchResultsUpdating& ,这个协议中只有一个方法,当搜索框中的值发生变化的时候,代理方法就会被调用)& & _searchController.searchResultsUpdater = self;& & _searchController.delegate = self;& & _searchController.searchBar.placeholder = @&漫画名/作者/类型&;& //& _searchController.searchBar.delegate =& & [self presentViewController:_searchController animated:YES completion:^{ // 当模态推出这个searchController的时候,需要把之前的searchBar隐藏,如果希望搜索的时候看不到热门搜索什么的,可以把这个页面给隐藏& & & & self.bar.hidden = YES;& & & & self.view.hidden = YES;&& & & && & }];}3.监听输入的关键字, 把输入的关键字,传到接口处去请求数据#pragma mark - UISearchResultsUpdating Method#pragma mark 监听者搜索框中的值的变化- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{& & // 1. 获取输入的值&& self.inputText = searchController.searchBar.text;& & [self afn1];}4. 请求数据并解析(我这里用的时AFN请求, 其他方法都可以,随意)// afnq请求数据(搜索数据)-(void)afn1{& & AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];& & NSLog(@&%d&, netWorkManager.isReachable);& & NSString *url_string = [NSString stringWithFormat:@&http://pappappap&, self.inputText];& & NSString *url = [url_string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];&& & NSLog(@&nnnnnn%@&, url);& & AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];& & manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@&text/html&];& & [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {& & & & [netWorkManager stopMonitoring];& & & & NSLog(@&kkk object = %@&, responseObject);& & & & NSMutableDictionary *dic = [NSMutableDictionary dictionary];& & & & dic = responseO& & & & self.searchResultDataArray = [NSMutableArray array];& & & & NSMutableDictionary *dic1 = [dic objectForKey:@&info&];& & & & NSMutableDictionary *dic2 = [dic1 objectForKey:@&data&];& & & & NSMutableArray *array = [dic2 objectForKey:@&items&];& & & & for (NSMutableDictionary *dic in array) {& & & & & & Comicslist *comics = [[Comicslist alloc] init];& & & & & & comics.bigbook_id = [NSString stringWithFormat:@&%@&, [dic objectForKey:@&id&]];& & & & & & comics.bigbook_name = [dic objectForKey:@&name&];& & & & & & comics.bigbook_author = [dic objectForKey:@&author&];& & & & & & comics.coverurl = [dic objectForKey:@&coverurl&];&& & & & & // NSString *key = [dic objectForKey:@&key_name&];&& & & & & // comics.key_name = [NSString stringWithFormat:@&%@%@&,comics.bigbook_name, comics.bigbook_author];& & & & & & [self.searchResultDataArray addObject:comics];& & & & }&& & & && & & & [_searchTVC.tableView reloadData];& & } failure:^(AFHTTPRequestOperation *operation, NSError *error) {& & & & NSLog(@&失败 %@&, error);& & }];&& &}5.设置显示搜索结果的tableView, 即self.searchTVC的tableView// 设置搜索tableView section个数- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{& & return 1;}// 设置搜索tableView cell个数- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{& & if (_searchResultDataArray.count == 0) {& & & & NSLog(@&33333&);& & & & return 1;& & }& & return _searchResultDataArray.count;}// 设置搜索tableView的cell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{& & static NSString *cellIdentifier = @&indenfy&;& & UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];& & if (cell == nil) {& & & & cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];& & }& & if (self.searchResultDataArray.count != 0) {& & Comicslist *comics = [self.searchResultDataArray objectAtIndex:indexPath.row];& & cell.textLabel.text = comics.bigbook_& & NSString *str = comics.& & NSURL *url = [NSURL URLWithString:str];& & UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];& & cell.imageView.image =& & }else{& & & cell.textLabel.text = @&没有查找的内容&;& & & & cell.imageView.image = nil;& & }& & return}// 设置cell高度&- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{& & return 100;}6. 设置搜索tableView 点击进入搜索结果- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 跳转操作}7.细节处理(1)当搜索页面消失的时候,让原先的搜索bar和View显示-(void)didDismissSearchController:(UISearchController *)searchController{& & self.bar.hidden = NO;& & self.view.hidden = NO;}(2)当View将要出现的时候, view显示- (void)viewWillAppear:(BOOL)animated{& & self.view.hidden = NO;}(3) 取消按钮触发方法, 点击取消后,self.bar和self.view显示出来-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{& & self.bar.hidden = NO;& & self.view.hidden = NO;}哈哈,激动人心的时刻,看一下运行的结果:1.进入搜索界面2.点击触发创建searchController3.进行搜索4.点击取消按钮后回原来的界面
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:14831次
排名:千里之外
原创:10篇问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
serachBar的位置改变不了吗?我知道是多了我那两个按钮的高度,但是怎么能让他上去呢?
(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
[self.kwSearchController.searchBar setFrame:CGRectMake(0, 0, KScreenWidth, 44)];
我是加在tableView的HeaderView上的在这个代理里修改位置也不好使
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
请问题主解决了吗?
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
首先:讲道理,你这个 TabBar 不应该是加在 headerView 上,因为 TabBar 应该是固定位置吧。其次:做这个界面,你最好分开处理视图,不使用 UISearchController,而是去使用自定义的 TabBar + UISearchBar + UITableView
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
self.definesPresentationContext = YES;就可以解决了但是,uisearchController还有其它问题,没用UISearchDisplayController好用。
当UISearchController是active时,就是触发时,你怎么解决标题栏的背景色的?不是navigation的背景。
searchbar自动上移-20,删除searchbar里面的UISearchBackground时。只能对searchbar背景有用,标题栏没有效果,就是显示运营商,wifi信号的背景
同步到新浪微博
分享到微博?
你好!看起来你挺喜欢这个内容,但是你还没有注册帐号。 当你创建了帐号,我们能准确地追踪你关注的问题,在有新答案或内容的时候收到网页和邮件通知。还能直接向作者咨询更多细节。如果上面的内容有帮助,记得点赞 (????)? 表示感谢。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
扫扫下载 AppiOS 用UISearchController自定义Search Bar | // TODO:> 博客详情
摘要: 在进行ios开发的时候,有时候涉及到搜索功能,实现搜索功能的方法有很多,可以是用自定义的搜索控件,也可以用sdk提供的UISearchController(ios8以后)、UISearchDisplayController(ios8之前);
在进行ios开发的时候,有时候涉及到搜索功能,实现搜索功能的方法有很多,可以是用自定义的搜索控件,也可以用sdk提供的UISearchController(ios8以后)、UISearchDisplayController(ios8之前);
下面介绍UISearchController使用方法及注意事项:
& & & & _searchController = [[UISearchController alloc] initWithSearchResultsController:_viewController];
& & & & _searchController.searchResultsUpdater = &//设置UISearchResultsUpdating协议代理
& & & & _searchController.delegate =&&&&&&&&//设置UISearchControllerDelegate协议代理
& & & & _searchController.dimsBackgroundDuringPresentation = NO;&&&&&&&&&&&&//是否添加半透明覆盖层
& & & & _searchController.hidesNavigationBarDuringPresentation = YES; & & //是否隐藏导航栏
& & & & [self.view addSubview:_searchController.searchBar];&&&&&&&&&&&&&&&&&&&&//此处重要一步,将searbar显示到界面上
另外需要注意在合适的地方添加下面一行代码
& & & & & & self.definesPresentationContext = YES;
这行代码是声明,哪个viewcontroller显示UISearchController,苹果开发中心的demo中的对这行代码,注释如下
&// know where you want UISearchController to be displayed
a、如果不添加上面这行代码,在设置hidesNavigationBarDuringPresentation这个属性为YES的时候,搜索框进入编辑模式会导致,searchbar不可见,偏移-64;
在设置为NO的时候,进入编辑模式输入内容会导致高度为64的白条,猜测是导航栏没有渲染出来
b、如果添加了上面这行代码,在设置hidesNavigationBarDuringPresentation这个属性为YES的时候,输入框进入编辑模式正常显示和使用;在设置为NO的时候,搜索框进入编辑模式导致向下偏移64,具体原因暂时未找到
人打赏支持
码字总数 24862
你加的是这行代码“[self.view addSubview:_searchController.searchBar];”吗
引用来自“HillYoung”的评论你加的是这行代码“[self.view addSubview:_searchController.searchBar];”吗没有加这句
引用来自“HillYoung”的评论你加的是这行代码“[self.view addSubview:_searchController.searchBar];”吗大神我给你发了私信 能看下吗
我的也是,请问你解决了吗?
我的也是,请问你解决了吗?
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥【学习ios之路:UI系列】(UISearchBar,UISearchDisplayController) 和UISearchController(iOS8新特性)
我的图书馆
【学习ios之路:UI系列】(UISearchBar,UISearchDisplayController) 和UISearchController(iOS8新特性)
1.UISearchBar(效果如下:)
①创建UISearchBar对象
&span style="font-size:18"&
//初始化,定义frame
UISearchBar *bar = [[UISearchBar alloc] initWithFrame:CGRectMake
(0, 50, self.view.frame.size.width, 80)];
//添加到控制器的视图上
[self.view addSubview:bar];&/span& ②UISerachBar的属性
&span style="font-size:18"&
//autocapitalizationType:包含4种类型,但是有时候键盘会屏蔽此属.
//1.autocapitalizationType????自动对输入文本对象进行大小写设置.
&bar.autocapitalizationType = UITextAutocapitalizationTypeW
& //2.autocorrectionType????自动对输入文本对象进行纠错
bar.autocorrectionType = UITextAutocorrectionTypeY
//3.设置title
bar.prompt = @"全部联系人";
//4.设置颜色
&& bar.tintColor& = [UIColor purpleColor];//渲染颜色
&& bar.barTintColor = [UIColor orangeColor];//搜索条颜色
bar.backgroundColor =& [UIColor purpleColor];//背景颜色,因为毛玻璃效果(transulent).
//5.translucent????指定控件是否会有透视效果
bar.translucent = YES;
//6.scopeButtonTitles(范围buttonTitle)
bar.scopeButtonTitles = @[@"精确搜索",@"模糊搜索"];
&&& bar.selectedScopeButtonIndex = 1;//通过下标指定默认选择的那个选择栏
//7.控制搜索栏下部的选择栏是否显示出来(需设置为YES 才能使用scopebar)
bar.showScopeBar = YES;
//8.设置搜索栏右边的按钮
bar.showsSearchResultsButton& = YES;//向下的箭头
bar.showsCancelButton = YES; //取消按钮
bar.showsBookmarkButton =& YES; //书签按钮
//9.提示内容
bar.placeholder = @"搜索";
//10.取消键盘操作
[searchBar resignFirstResponder];&
//11.设置代理
//UISearchBar不执行搜索行为,必须使用delegate,当输入搜索文本、点击button按钮后,代理的方法
会完成搜索对应的操作。
//.控件的委托,委托要遵从UISearchBarDelegate协议,默认是nil
bar.delegate =
③代理要试实现的协议方法
1).输入编辑事件处理
&span style="font-size:18"&? searchBar:textDidChange:
? searchBar:shouldChangeTextInRange:replacementText:
? searchBarShouldBeginEditing:
? searchBarTextDidBeginEditing:
? searchBarShouldEndEditing:
? searchBarTextDidEndEditing:&/span& 2).点击按钮事件处理
&span style="font-size:18"&? searchBarBookmarkButtonClicked:
? searchBarCancelButtonClicked:
? searchBarSearchButtonClicked:
? searchBarResultsListButtonClicked:&/span& 3).点击Scope按钮事件处理
&span style="font-size:18"&? searchBar:selectedScopeButtonIndexDidChange:&/span&
2.UISearchDisplayController(注:iOS8以上已经弃用)
结合UISearchBar实现效果如下,实现搜索功能.
提示:检测Xcode系统版本代码如下:
&span style="font-size:18"&[[[UIDevice currentDevice] systemVersion] floatValue] &= 8.0 ? YES: NO;&/span& ①.创建对象
&span style="font-size:18"&
//需要创建UISearchBar对象,这里将对象都定义成了属性
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
//设置UISearchBar属性,上面有UISearchBar详细介绍.
&&& self.searchBar.placeholder = @"enter province name";
&&& self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
&& self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeAllC
&&& self.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:
&span style="color:#FF0000;"&
&/span&@"All",@"A",@"B",@"C",@"D" ,nil];
&&& self.searchBar.showsScopeBar = YES;
&&& self.searchBar.keyboardType = UIKeyboardTypeNamePhoneP
&&& self.searchBar.showsBookmarkButton = YES;
//将seachBar作为控制器的透视图,视图控制器,继承UITableViewController
&&& self.tableView.tableHeaderView = _searchB
//将UIsearchBar添加到UIdSearchDispalyController上
self.displayController = [[UISearchDisplayController alloc]
&initWithSearchBar:_searchBar contentsController:self];&/span& 注:searchBar????在searchdisplaycontroller初始化后,searchbar是不可修改的,是readonly属性的.
②配置UISearchDisplayController的属性
&span style="font-size:18"&
//active????是搜索界面可视化,默认为no,可用setActive方法设置.
self.displayController.active = YES;
&&& // searchResultsDataSource????搜索结果的数据源,代理对象(UITableViewDataSource)
&&& self.displayController.searchResultsDataSource =
//searchResultsDelegate????搜索结果的委托,服从协议UITableViewDelegate&&
&self.displayController.searchResultsDelegate =//
&/span& ③实现
&span style="font-size:18"&&
/*searchDisplayController 自身有一个searchResultsTableView,
所以在执行操作的时候首先要判断是否是搜索结果的tableView,如果是显示的就是搜索结果的数据,
如果不是,是TableView自身的view,则需要显示原始数据。*/
if (tableView == self.tableView) {
return self.dataArray.
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"self contains [cd] %@",self.searchBar.text];
[[NSMutableArray alloc] initWithArray:
[self.dataArray filteredArrayUsingPredicate:predicate]];
return self.arr.
④使用UISearchDisplayDelegate的委托方法进行搜索操作:
1).搜索状态改变事件处理方法:
&span style="font-size:18"&? searchDisplayControllerWillBeginSearch:
? searchDisplayControllerDidBeginSearch:
? searchDisplayControllerWillEndSearch:
? searchDisplayControllerDidEndSearch:
2).装载和卸载tableview事件处理方法:
&span style="font-size:18"&? searchDisplayController:didLoadSearchResultsTableView:
? searchDisplayController:willUnloadSearchResultsTableView:&/span&
3).显示和隐藏tableview事件处理方法:
&span style="font-size:18"&? searchDisplayController:willShowSearchResultsTableView:
? searchDisplayController:didShowSearchResultsTableView:
? searchDisplayController:willHideSearchResultsTableView:
? searchDisplayController:didHideSearchResultsTableView:&/span& 4).搜索条件改变时响应事件处理方法:
&span style="font-size:18"&? searchDisplayController:shouldReloadTableForSearchString:
? searchDisplayController:shouldReloadTableForSearchScope&/span&
3.UISearchController(iOS8新特性)
UISearchController实现和上述效果基本一致,适用于iOS8以上版本
实现如下图搜索效果
1)新建控制器,继承与UITableViewController,在extension中定义属性
&span style="font-size:18"&//存储原来的数据
@property (nonatomic, retain) NSArray *dataA
//存储检索后的数据
@property (nonatomic, retain) NSArray *
&/span& 2).加载数据,懒加载
&span style="font-size:18"&- (NSArray *)dataArr {
if (!_dataArr) {
&self.dataArr = [NSArray arrayWithObjects:
@"Allan",@"Abbbb",@"Acccc",@"Bccccc",@"Cddddffk",@"Cddkllll",
@"Ekkflfl",@"Ekljljfg" ,@"Leslie",@"Mm",@"Meinv",@"Meihi",@"Catilin",
@"Arron", @"211", @"232", @"243", @"264", @"285", @"106", @"311",
@"432", @"543", @"664", @"785", @"806", nil];
return _dataA
//如果检索后的数据为空,将原有数据赋值给检索数据
- (NSArray *)arr {
&&& if (!_arr) {
&&&&&&& self.arr = self.dataA
&&& return _
&/span& 3.加载UISearchController对象
&font size="4"&- (void)viewDidLoad {
[super viewDidLoad];
//cell重用机制,调用系统的
[self.tableView registerClass:[UITableViewCell class]
&forCellReuseIdentifier:@"lock"];
//创建搜索条,将自身设置为展示结果的控制器
UISearchController *searchVC =[[UISearchController alloc]
initWithSearchResultsController:nil];
//设置渲染颜色
searchVC.searchBar.tintColor = [UIColor orangeColor];
//设置状态条颜色
searchVC.searchBar.barTintColor = [UIColor orangeColor];
&span style="font-size:18"&
//设置开始搜索时背景显示与否(很重要) &/span&
&span style="font-size:18"&
searchVC.dimsBackgroundDuringPresentation = NO; &/span&
&span style="font-size:18"&
//适应整个屏幕
&[searchVC.searchBar sizeToFit];
&span style="font-size:18"&
//设置显示搜索结果的控制器
&span style="font-size:18"& searchVC.searchResultsUpdater = &/span&&span style="font-size:18"& //协议(UISearchResultsUpdating)
//将搜索控制器的搜索条设置为页眉视图
self.tableView.tableHeaderView = searchVC.searchB
&/span&&/span&&/span&&/font&
4).实现协议中的方法,必须实现
&span style="font-size:18"&- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
//谓词检测
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"self contains [cd] %@", searchController.searchBar.text];
//将所有和搜索有关的内容存储到arr数组
&self.arr = [NSMutableArray arrayWithArray:
[self.dataArr filteredArrayUsingPredicate:predicate]];
//重新加载数据
&& [self.tableView reloadData];&
5).设置UITabelViewController中的其它
&span style="font-size:18"&#pragma mark - Table view data source
//设置有多少个分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
//每个分区有多少行数据
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section {
return self.arr.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
self.cell = [tableView dequeueReusableCellWithIdentifier:@"lock"
forIndexPath:indexPath];
//设置cell上展示的内容,即搜索后的数据
self.cell.textLabel.text = self.arr[indexPath.row];
return self.
}&/span& 注.以上是实现搜索框搜索空能.(当搜索内容为空时,返回的时所有数据,如果搜索内容为空,返回空时,需要进行其它修改操作.)
TA的最新馆藏

我要回帖

更多关于 光纤猫 交换机 路由器 的文章

 

随机推荐