首页 文章 精选 留言 我的

精选列表

搜索[微服务快速开发平台],共10000篇文章
优秀的个人博客,低调大师

iOS开发-plist文件增删改查

plist第一次看到这个后缀名文件的时候感觉怪怪的,不过接触久了也就习以为常了,plist是Property List的简称可以理解成属性列表文件,主要用来存储串行化后的对象的文件。扩展名为.plist,因此被称为plist文件,xCode中默认的是一种树状的结构展现出来数据,可视化的动态增删改查,非常人性化,不过最终的结果是以XML形式存储的,Plist文件可以用于存储用户的一些设置信息,具体根据需求而定。 简单创建文件 简单创建文件就是说可以直接从xCode创建,右击项目new File,可以添加一个plist文件: 创建一个UserData.plist文件,之后的内容如下: 右击open as->source code,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version= "1.0" encoding= "UTF-8" ?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" > <plist version= "1.0" > <dict> <key>Login</key> <dict> <key>UserName</key> <string>FlyElephant</string> <key>UserPassWord</key> <string>123456</string> </dict> </dict> </plist> 读取设置的信息: 1 2 3 4 5 6 //读取Property List文件 NSString *userDataPath = [[ NSBundle mainBundle] pathForResource:@ "UserData" ofType:@ "plist" ]; NSMutableDictionary *data = [[ NSMutableDictionary alloc] initWithContentsOfFile:userDataPath]; NSLog (@ "%@" ,data); NSLog (@ "用户名:%@ 密码:%@" , data[@ "Login" ][@ "UserName" ],data[@ "Login" ][@ "UserPassWord" ]); [data setObject:@ "登录信息" forKey:@ "Login" ]; 增删改查 文件添加,上面是应用程序中添加文件,这个时候可以选择代码在沙盒中添加,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 NSArray *sandboxpath= NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES ); //获取完整路径 NSString *documentsDirectory = [sandboxpath objectAtIndex:0]; NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@ "sandbox.plist" ]; //存储根数据 NSMutableDictionary *rootDic = [[ NSMutableDictionary alloc ] init]; //字典中的详细数据 NSMutableDictionary *userDataDic = [[ NSMutableDictionary alloc]init]; [userDataDic setObject:@ "Flephant" forKey:@ "UserName" ]; [userDataDic setObject:@ "http://www.cnblogs.com/xiaofeixiang/" forKey:@ "UserPassWord" ]; [rootDic setObject:userDataDic forKey:@ "Login" ]; //写入文件 [rootDic writeToFile:plistPath atomically: YES ]; NSLog (@ "%@" , NSHomeDirectory ()); NSLog (@ "写入成功" ); 路径如下,具体路径获取上一篇文章已经可以看到: 读取数据: 1 2 3 4 5 6 7 //获取路径 NSArray *sandboxpath= NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES ); NSString *filePath = [[sandboxpath objectAtIndex:0] stringByAppendingPathComponent:@ "sandbox.plist" ]; NSLog (@ "%@" , NSHomeDirectory ()); //获取数据 NSMutableDictionary *searchdata = [[ NSMutableDictionary alloc] initWithContentsOfFile:filePath]; NSLog (@ "%@" ,searchdata); 修改文件: 1 2 3 4 5 6 7 8 9 10 11 12 13 //获取路径 NSString *filepath = [[ NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES )objectAtIndex:0]stringByAppendingPathComponent:@ "sandbox.plist" ]; //所有的数据列表 NSMutableDictionary *datalist= [[[ NSMutableDictionary alloc]initWithContentsOfFile:filepath]mutableCopy]; //获取Login节点 NSMutableDictionary *loginData = [datalist objectForKey:@ "Login" ]; [loginData setValue: @ "FlyElephant" forKey:@ "UserName" ]; [loginData setValue: @ "123456" forKey:@ "UserPassWord" ]; [datalist setValue:loginData forKey:@ "Login" ]; [datalist writeToFile:filepath atomically: YES ]; NSLog (@ "修改成功" ); 删除文件: 1 2 3 4 5 6 NSFileManager *manager=[ NSFileManager defaultManager]; //文件路径 NSString *filepath = [[ NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES )objectAtIndex:0]stringByAppendingPathComponent:@ "sandbox.plist" ]; if ([manager removeItemAtPath:filepath error: nil ]) { NSLog (@ "文件删除成功" ); } 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4263498.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-图片查看(ScrollView+UIPageControl)

上周没事写了一个简单的图片查看,上次的查看只用到了一个UIImageView,不断的替换背景图片,实现图片之间的切换。通过ScrollView可以很简单的是实现图片之间的查看,设置setPagingEnabled通过坐标,宽度的设置,可以简单实现一个图片的简单分页查看显示,当然如果你有需求说需要进行所谓的无限循环,在开始和结束的时候的设置一下事件,常用的新闻客户端,图片新闻查看的时候很少有进行最后的时候跳到第一页,一般都是最后的时候都是推荐相关内容,多说了两句,开始吧: ScrollView图片分页 控件跟上篇文章一样,就是ScrollView: 拖入三张图片到项目中,之前的文章有演示,下次写博客的考虑换图,初始化ScrollView: 1 2 3 4 5 6 7 8 9 10 NSArray *imageArr=@[@ "girl0.jpg" ,@ "girl1.jpg" ,@ "girl2.jpg" ]; CGFloat width= self .scrollView.bounds.size.width; CGFloat height= self .scrollView.bounds.size.height; for ( NSInteger i=0; i<[imageArr count]; i++) { UIImage *image=[UIImage imageNamed:imageArr[i]]; UIImageView *imageView=[[UIImageView alloc] initWithImage:image]; [imageView setFrame:CGRectMake(i*width, 0, width, height)]; [_scrollView addSubview:imageView]; } 这里没有写注释,稍微多说一句就是bounds是边界,可以理解为就是控件中的ScrollView的宽度和高度,也就是上一张图片展示的宽度和高度,设置周围的边界: 1 [ self .scrollView setBounces: NO ]; 设置水平方向的滚动条: 1 [ self .scrollView setShowsHorizontalScrollIndicator: NO ]; 设置ScrollView的总体的宽度(关键): 1 [ self .scrollView setContentSize:CGSizeMake([imageArr count]*width, height)]; 设置分页: 1 [ self .scrollView setPagingEnabled: YES ]; 演示效果: UIPageControl和ScrollView图片分页 UIPageControl如果稍微弄过点前端可以理解为焦点图,大概通过指示,iOS中是小圆点,Android需要美工给自己切图或者说自力更生,iOS相对来说还是比较人性的,先定义一个UIPageControl: 1 @property ( nonatomic ,strong) UIPageControl *pageControl; 初始化UIPageControl设置大小和位置: 1 2 3 4 5 self .pageControl=[[UIPageControl alloc] init]; self .pageControl.backgroundColor=[UIColor clearColor]; [ self .pageControl setBounds:CGRectMake(0, 0,200, 100)]; [ self .pageControl setCenter:CGPointMake(width/2,height/2+200.0)]; 设置当前页和页大小: 1 2 self .pageControl.numberOfPages=[imageArr count]; self .pageControl.currentPage=0; 设置当前指示和其他指示: 1 2 3 [ self .pageControl setCurrentPageIndicatorTintColor:[UIColor greenColor]]; [ self .pageControl setPageIndicatorTintColor:[UIColor yellowColor]]; 设置滑动的时候改变UIPageControl和通过UIPageControl改变ScrollView: 1 2 3 [_scrollView setDelegate: self ]; [ self .pageControl addTarget: self action: @selector (switchPage:) forControlEvents:UIControlEventValueChanged]; [ self .view addSubview:_pageControl]; 滑动的时候改变UIPageControl指示通过委托设置,具体可参考上篇文章: 1 2 3 4 -( void )scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSInteger currentPage=scrollView.contentOffset.x/ self .view.bounds.size.width; [ self .pageControl setCurrentPage:currentPage]; } UIPageControl改变ScrollView: 1 2 3 4 5 - ( void )switchPage:( id )sender{ UIPageControl *currentControl=(UIPageControl *)sender; NSInteger currentPage=currentControl.currentPage; [_scrollView setContentOffset:CGPointMake(currentPage* self .view.bounds.size.width, 0)] ; } 看下具体的效果: 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4242919.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android初级开发第九讲--动画

本文来自http://blog.csdn.net/liuxian13183/,引用必须注明出处! Android中动画的应用,在应用管理软件、购物软件、追星软件等比较广泛;比如常见的进度条设计,此处尤其指圆形的那种。比如清理小火箭,从下向上飞出;比如清理软件提示,由深色渐变成浅色。这些都是动画的应用场景。 Android动画分为两种,一种叫帧动画,就像flash一样,学名Frame,进度条一般使用这种;另一种叫补间动画,学名Tween,可以移动位置、变化颜色、变换大小、翻转变化。 先说帧动画 <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@mipmap/icon_s01" android:duration="30" /> <item android:drawable="@mipmap/icon_s02" android:duration="30" /> <item android:drawable="@mipmap/icon_s03" android:duration="30" /> </animation-list> onshot的意思是,true只播放一遍,false循环播放;item项指每隔duration展示的图片 应用: 先写布局 <ImageView android:id="@+id/loading_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:background="@drawable/anim_progress_round"/> 再执行代码 ImageView loadingImage = child.findViewById(R.id.loading_iv); AnimationDrawable animation = (AnimationDrawable) loadingImage.getBackground(); if (animation.isRunning()) { animation.stop(); } animation.start(); 获得背景的AnimationDrawable对象,执行start方法即可。 补间动画: 基类Animation,子类ScaleAnimation、AlphaAnimation、RotateAnimation、TranlateAnimation,分别用于大小变换、色彩变换、翻转变换和位移变换。 常用方法有setDutation-设置运行时间,setFillAfter-设置运行结束是否保持最后状态,setFillBefore-设置运行结束是否保质最初状态,setRepeatCount-设置重复执行次数;setRepeatMode-设置重复类型,如REVERSE会倒着再执行repeatCount遍;setInterpolater-设置插补器,可以让控件回弹,控制速度。 //accelerate_decelerate_interpolator先慢后快再慢linear_interpolator匀速decelerate_interpolator先快后慢 mAnimationTranslate.setInterpolator(mContext, android.R.anim.decelerate_interpolator); 例: mAnimationTranslate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); mAnimationTranslate.setDuration(3000); mAnimationTranslate.setRepeatMode(Animation.ABSOLUTE); mAnimationTranslate.setRepeatCount(0); mRocketIv.startAnimation(mAnimationTranslate);设置相关参数,执行startAnimation即可。 ScaleAnimation:fromXScale-X轴方向缩放比例,toXScale、fromYScale和toYScale同理;pivoteX起点X坐标,pivoteY同理。 AlphaAnimation:fromAlpha-起始透明度,toAlpha-最终透明度。 RotateAnimation:fromDegress-起始角度,toDegress-最终角度,正数为顺时针,负数为逆时针。 TranslateAnimation:fromXType-起始位移类型,fromYType同理;fromXValue-起始X坐标,fromYValue同理; 从左边折出来 ScaleAnimation animation = new ScaleAnimation(0f, 1f, 1f, 1f); animation.setDuration(1000);//设置动画持续时间 mChannelLayout.setAnimation(animation); 从左上角弹出来 ScaleAnimation animation = new ScaleAnimation(0f, 1f, 0f, 1f); animation.setDuration(1000);//设置动画持续时间 mChannelLayout.setAnimation(animation); 从左向右的动画: AnimationUtils.makeInAnimation(this, true); 从右回到左的动画: AnimationUtils.makeOutAnimation(this, false); 最后AnimationSet可以对以上四种补间动画类型进行组合,制造出更加炫酷的效果。

优秀的个人博客,低调大师

iOS开发-多线程NSOperation和NSOperationQueue

上一篇文章稍微提及了一下NSThread的使用,NSThread能直观地控制线程对象,不过需要自己管理线程的生命周期,线程同步,用起来比较繁琐,而且比较容易出错。不过Apple给出了自己的解决方案NSOperation,它本身是抽象基类,因此必须使用它的子类,使用NSOperation子类的方式有NSInvocationOperation和NSBlockOperation两种方式,先补充一下NSThread的用法: NSThread获取当前线程: 1 [ NSThread currentThread] performSelectorInBackground可以更新UI,不建议使用: 1 2 3 4 5 - ( IBAction )update:( id )sender { [ self performSelectorInBackground: @selector (changeImage) withObject: nil ]; } 图片背景更新: 1 2 3 4 -( void )changeImage{ NSLog (@ "线程执行完之后更新图片" ); self .myImageView.image=[UIImage imageNamed:[ NSString stringWithFormat:@ "Thread2.jpg" ]]; } NSInvocationOperation和NSBlockOperation 这两种方式都很简单,其中NSInvocation的调用方式类似于NSThread,NSBlockOperation如果对Block有一点了解就可以,如果不明白的可以参考本人之前的Block文章Object-C-代码块Block回顾,那么接下来的使用方式就很简单: 先来看下NSInvocationOperation的实例化方式: 1 2 3 4 //初始化 NSInvocationOperation *myInvocationOperation= [[ NSInvocationOperation alloc] initWithTarget: self selector: @selector (operationTaskMethod) object: nil ]; //启动 [myInvocationOperation start]; 调用方法: 1 2 3 4 -( void )operationTaskMethod{ NSLog (@ "NSInvocationOperation初始化执行" ); } NSBlockOperation的方式: 1 2 3 4 NSBlockOperation *blockOperation=[ NSBlockOperation blockOperationWithBlock:^{ NSLog (@ "BlockOperation块执行" ); }]; [blockOperation start]; 两种方式很方便,这个时候可以使用NSOperationQueue作为一个队列将线程包含在一起,首先定义一个NSOperationQuene: 1 @property (strong, nonatomic ) NSOperationQueue *myOperationQuene; 这个时候需要调用: 1 2 3 4 5 6 7 8 9 10 11 NSInvocationOperation *myInvocationOperation= [[ NSInvocationOperation alloc] initWithTarget: self selector: @selector (operationTaskMethod) object: nil ]; NSBlockOperation *blockOperation=[ NSBlockOperation blockOperationWithBlock:^{ NSLog (@ "BlockOperation块执行" ); }]; self .myOperationQuene=[[ NSOperationQueue alloc]init]; [ self .myOperationQuene addOperation:myInvocationOperation]; [ self .myOperationQuene addOperation:blockOperation]; 上面最后的结果不确定,线程执行的顺序没法确定,如果想确定的按照顺序执行,需要添加一个依赖: 1 [blockOperation addDependency:myInvocationOperation]; 添加依赖之后的,每次输出的结果一定是这样的: 1 2 2015-02-11 07:56:13.457 ThreadDemo[657:15033] NSInvocationOperation 初始化执行 2015-02-11 07:56:13.457 ThreadDemo[657:15034] BlockOperation块执行 自定义NSOperation 每次一看到自定义,就感觉瞬间有了档次,然后参考一下前人的经验,不过网上的博客有的不好说,那感觉就是我想吃一个鸡腿,却拿到了一个鸡腿堡,需要的不需要的都要自己一起吸收。NSInvocationOperation和NSBlockOperation这两种方式不能满足业务需求,这个时候需要自定义的NSOperation,自定义的有两种分为非并发(NonConcurrent)和并发(Concurrent)两种形式,本文介绍非并发形式。 新建一个继承自NSOperation的MyCustomOperation,然后实现一下main方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 // // MyCustomOperation.h // ThreadDemo // // Created by keso on 15/2/11. // Copyright (c) 2015年 keso. All rights reserved. // #import <Foundation/Foundation.h> @interface MyCustomOperation : NSOperation @property (strong, nonatomic ) NSString *customdata; -( void )initData:( NSString *)data; @end NSOperation对象需要定期地调用isCancelled方法检测操作是否已经被取消,如果返回YES(表示已取消),则立即退出执行回收内存资源。所有NSOperation子类,一般用于代码比较容易终止的地方,在循环的每次迭代过程中,如果每个迭代相对较长可能需要调用多次和没有执行工作之前调用。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 // // MyCustomOperation.m // ThreadDemo // // Created by keso on 15/2/10. // Copyright (c) 2015年 keso. All rights reserved. // #import "MyCustomOperation.h" @implementation MyCustomOperation - ( void )initData:( NSString *)data{ if ( self ==[ super init]) _customdata= data; } - ( void )main { @try { BOOL isDone = NO ; NSLog (@ "循环之前的调用" ); while (![ self isCancelled] && !isDone) { // Do some work and set isDone to YES when finished NSLog (@ "已经运行成功了" ); isDone= YES ; } } @catch (...) { NSLog (@ "出现异常,请检查代码~" ); } } @end 如果需要调用定义的NSOPeration实例化之后Start即可: 1 2 MyCustomOperation *customOperation=[[MyCustomOperation alloc] init]; [customOperation start]; 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4285102.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-搜索栏UISearchBar和UISearchController

iOS中UISearchDisplayController用于搜索,搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社交,O2O还是在线教育等都会有一个搜索栏的实现,不过彼此实现效果是不一样的。iOS中的搜索栏实现起来相对简单一点,网上也有很多参考资料,不过靠谱的不是很多,很多都是iOS 8.0之前的实现,iOS 8.0上的实现貌似很少看到,可以运行,不过会看到searchDisplayController' is deprecated: first deprecated in iOS 8.0警告,看了一些老外的代码,使用了一下UISearchController感觉还是非常不错的。 UISearchBar和UISearchDisplayController 是网上最常见的也算是最简单的,也有使用Searh Bar Search Display Controller的控件的,本文就简单的使用Search Bar和UITableView实现搜索Demo的,最上面的就是搜索栏,之前的就是TableView: 为了实现搜索需要声明委托UISearchBarDelegate,UISearchDisplayDelegate,其中搜索主要使用的就是UISearchDisplayDelegate,具体代码实现过程: 声明字段: 1 2 3 @property (strong, nonatomic ) NSMutableArray *dataList; @property (strong, nonatomic ) NSMutableArray *searchList; 初始化数据: 1 2 3 4 5 self .dataList=[ NSMutableArray arrayWithCapacity:100]; for ( NSInteger i=0; i<100; i++) { [ self .dataList addObject:[ NSString stringWithFormat:@ "%ld-FlyElephant" ,( long )i]]; } 设置区域: 1 2 3 4 //设置区域 -( NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } 设置区域的行数(重点),这个就是使用委托之后需要需要判断是一下是否是需要使用Search之后的视图: 1 2 3 4 5 6 7 -( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section{ if (tableView == self .searchDisplayController.searchResultsTableView) { return [ self .searchList count]; } else { return [ self .dataList count]; } } 同样的返回单元格也有两种情况,一种是初始化数据,一种是过滤之后的数据视图: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{ static NSString *flag=@ "cellFlag" ; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag]; if (cell== nil ) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag]; } if (tableView== self .searchDisplayController.searchResultsTableView) { [cell.textLabel setText: self .searchList[indexPath.row]]; } else { [cell.textLabel setText: self .dataList[indexPath.row]]; } return cell; } UISearchBarDelegate中的开始和结束的事件: 1 2 3 4 5 6 7 8 9 - ( BOOL )searchBarShouldBeginEditing:(UISearchBar *)searchBar{ NSLog (@ "搜索Begin" ); return YES ; } - ( BOOL )searchBarShouldEndEditing:(UISearchBar *)searchBar{ NSLog (@ "搜索End" ); return YES ; } 搜索时过滤数据: 1 2 3 4 5 6 7 8 9 10 11 12 - ( BOOL )searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:( NSString *)searchString{ // 谓词的包含语法,之前文章介绍过http://www.cnblogs.com/xiaofeixiang/ NSPredicate *preicate = [ NSPredicate predicateWithFormat:@ "SELF CONTAINS[c] %@" , searchString]; if ( self .searchList!= nil ) { [ self .searchList removeAllObjects]; } //过滤数据 self .searchList= [ NSMutableArray arrayWithArray:[_dataList filteredArrayUsingPredicate:preicate]]; //刷新表格 return YES ; } 最终效果如下: UISearchController实现搜索 UISeachBar通过UISearchDisplayDelegate实现上面的效果是没有问题的,网上也有很多类似的实现效果,不过是警告的,信息如下: 'searchDisplayController' is deprecated: first deprecated in iOS 8.0,这么明显一个警告总不能视而不见吧,在StackOverFlow中发现UISearchDisplayController is deprecatedinIOS8.0, and recommended to use UISearchController instead,也就是说iOS8.0不推荐UISearchDisplayController,也就是不推荐使用UISearchDisplayDelegate,但是可以通过UISearchController实现UISearchResultsUpdating这个委托实现上面的效果; 视图中中需要声明UISearchResultsUpdating: 1 2 3 4 @interface ViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchResultsUpdating> @end 属性声明: 1 @property ( nonatomic , strong) UISearchController *searchController; 需要自己初始化一下UISearchController: 1 2 3 4 5 6 7 8 9 10 11 _searchController = [[UISearchController alloc] initWithSearchResultsController: nil ]; _searchController.searchResultsUpdater = self ; _searchController.dimsBackgroundDuringPresentation = NO ; _searchController.hidesNavigationBarDuringPresentation = NO ; _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 .tableView.tableHeaderView = self .searchController.searchBar; 之前是通过判断搜索时候的TableView,不过现在直接使用self.searchController.active进行判断即可,也就是UISearchController的active属性: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 //设置区域的行数 -( NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:( NSInteger )section{ if ( self .searchController.active) { return [ self .searchList count]; } else { return [ self .dataList count]; } } //返回单元格内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{ static NSString *flag=@ "cellFlag" ; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag]; if (cell== nil ) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag]; } if ( self .searchController.active) { [cell.textLabel setText: self .searchList[indexPath.row]]; } else { [cell.textLabel setText: self .dataList[indexPath.row]]; } return cell; } 具体调用的时候使用的方法也发生了改变,这个时候使用updateSearchResultsForSearchController进行结果过滤: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -( void )updateSearchResultsForSearchController:(UISearchController *)searchController { NSString *searchString = [ self .searchController.searchBar text]; NSPredicate *preicate = [ NSPredicate predicateWithFormat:@ "SELF CONTAINS[c] %@" , searchString]; if ( self .searchList!= nil ) { [ self .searchList removeAllObjects]; } //过滤数据 self .searchList= [ NSMutableArray arrayWithArray:[_dataList filteredArrayUsingPredicate:preicate]]; //刷新表格 [ self .tableView reloadData]; } 效果演示: 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4273620.html,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册