我们要实现的效果如下。
1.修改ControlView.h,即添加变量dict,用于存储TabelView的数据源。
#import <UIKit/UIKit.h> @interface IkrboyViewController5 : UIViewController{ NSMutableDictionary *dict; } @end
2.在ControlView.m添加如下修改
- (void)viewDidLoad { [super viewDidLoad]; [self initTableViewData]; // Do any additional setup after loading the view. } -(void)initTableViewData{ NSBundle *bundle = [NSBundle mainBundle]; NSString *plistPath = [bundle pathForResource:@"user_head" ofType:@"plist"]; NSArray *dataArr = [[NSArray alloc] initWithContentsOfFile:plistPath]; //将所有数据分为三组 NSMutableArray *arr1 = [NSMutableArray array]; NSMutableArray *arr2 = [NSMutableArray array]; NSMutableArray *arr3 = [NSMutableArray array]; dict = [NSMutableDictionary dictionary]; [dict setObject:arr1 forKey:@"Group1"]; [dict setObject:arr2 forKey:@"Group2"]; [dict setObject:arr3 forKey:@"Group3"]; //设置划分数据的依据,即根据index分三组,index为0-1的为第一组,2-4为第二组,5为第三组 for(NSInteger index = 0; index < [dataArr count]; index++){ NSDictionary *item = [dataArr objectAtIndex:index]; if(index<2){ [arr1 addObject:item]; } else if(index>=2&&index<5){ [arr2 addObject:item]; } else if(index>=5){ [arr3 addObject:item]; } } }
3.初始化TableView
//分为多少个分组 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [[dict allKeys] count]; } //每个分组的数据单元个数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { switch(section) { case 0: { return [[dict objectForKey:@"Group1"] count]; } case 1: { return [[dict objectForKey:@"Group2"] count]; } case 2: { return [[dict objectForKey:@"Group3"] count]; } } return 0; } //分组的标题,不实现下面的方法,不显示分组标题 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { //dict allKeys取出的key arr无顺序,需进行排序 NSArray *arr = [[dict allKeys] sortedArrayUsingSelector:@selector(compare:)]; return [arr objectAtIndex:section]; } //列表右侧的索引提示,不实现下面的方法,不显示右侧索引 -(NSArray *) sectionIndexTitlesForTableView: (UITableView *) tableView { //dict allKeys取出的key arr无顺序,需进行排序 NSArray *arr = [[dict allKeys] sortedArrayUsingSelector:@selector(compare:)]; return arr; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"myTableCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; NSUInteger row = [indexPath row]; NSUInteger section = [indexPath section]; NSArray *arr; switch (section) { case 0: arr = [dict objectForKey:@"Group1"]; break; case 1: arr = [dict objectForKey:@"Group2"]; break; case 2: arr = [dict objectForKey:@"Group3"]; break; default: break; } NSDictionary *rowDict = [arr objectAtIndex:row]; cell.textLabel.text = [rowDict objectForKey:@"itemName"]; NSLog(@"cell.label.text = %@",[rowDict objectForKey:@"itemName"]); NSString *imagePath = [rowDict objectForKey:@"itemImagePath"]; cell.imageView.image = [UIImage imageNamed:imagePath]; NSLog(@"cell.image.image = %@",imagePath); cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } //选中Cell响应事件 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失 NSUInteger row = [indexPath row]; NSUInteger section = [indexPath section]; NSArray *arr; switch (section) { case 0: arr = [dict objectForKey:@"Group1"]; break; case 1: arr = [dict objectForKey:@"Group2"]; break; case 2: arr = [dict objectForKey:@"Group3"]; break; default: break; } NSDictionary *rowDict = [arr objectAtIndex:row]; NSString *userName = [rowDict objectForKey:@"itemName"]; NSLog(@"userName=%@",userName); }
相关推荐
此实例动态生成分节表视图。一个表可以有多个节,节也有头有脚,分节是添加索引和分组的前提。
用法将时间表视图添加到用户界面时,应用程序的主要工作是管理与该时间表视图关联的事件数据。 时间表视图从数据源对象获取数据,该数据源对象符合TimetableDataSource协议,由您的应用提供。 时间表视图中的数据被...
接下来掌握了如何实现简单表视图和分节表视图,以及表视图中索引、搜索栏、分组的使用。然后学习了如何对表视图单元格进行删除、插入、移动等操作。最后介绍表视图UI设计模式方面的内容。 第6章“视图控制器与导航...
效果微信效果图:toast效果图:功能及优点主要功能及优点如下:当滑动UITableView列表时,索引视图的索引位置会跟着移动;UITableView和SCIndexView之间手势和事件不冲突,操作其中一个视图,另一个视图失效;当滑动...
ZFTokenField iOS自定义视图,可让您在其中添加令牌视图,例如NSTokenField安装pod 'ZFTokenField' 用法ZFTokenFieldDataSource 您需要在数据源类中实现这些lineHeightForTokenInField:tokenField:返回所需的行高。...
因此,当您更改contentOffset时,每个视图将按其在subviews数组中的索引定义的距离移动。 DVParallaxView非常易于使用。 只需将其插入项目,创建实例,添加子视图并根据需要移动它即可,方法是设置contentOffset或...
通讯录排序 支持右边索引自定义视图 ABCD...间隙大小和与右边间隙大小调节 点击索引跳转到指定位置,滑动索引时美观动画效果!
一个类似于安卓ViewPager的开源库 - iOS ViewPager 高级库 支持 iPhone/ipad/ipod 相关方法 pragma mark - version 1.0 /** * 初始化 YFViewPager的方法 * * @param frame frame * @param titles 标题...
iOS,UItabelView代理方法详解:tabelView 表视图, 是iOS中用来显示以及能够编辑一系列具有相同数据结构的信息列表的控件, UITabelView继承自UIScrollView, 所以能够滑动, 但是只能在垂直方向滑动, 而且只有一列, ...
LazyPages是一个高度可定制的库,可帮助您显示与索引同步的视图控制器的可滚动列表。 它是用Swift 5为iOS 11+编写的。 要求 iOS 11+ Xcode 12.2+ 特征 延迟加载视图控制器,这使我们在初始化LazyPages时不会将...
简介: Book Description Get a rapid introduction to iPhone, iPad, and iPod touch programming. With this easy-to-follow guide, you’ll learn the steps necessary for developing your first marketable...索引
//索引为0表示先添加的子视图,跟子视图的tag没有关系 //交换两个子视图的先后位置 [self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; exchange交换 Subview 代替 //remove 移除 from 从 superview ...
可监听当前图片的索引 可监听点击事件 介绍 集成非常简单 LBBanner的自定义能力也非常强 性能也是尽量做到最佳 在LBBannerImgs文件夹下面有几张默认的图片,使用时可以删除掉,在LBBannerTools文件夹下面是...
它引入了路径索引集合的概念,可以组合并用作表和集合视图控制器的视图模型,它们的项目充当相应单元格的视图模型。 用法 要运行示例项目, pod install克隆 repo,然后从 Example 目录运行pod install 。 要求 ...
然后实例化视图并添加行和事件: - (void)viewDidLoad { [super viewDidLoad]; TimeLineChartView* timeLineChartView = [[TimeLineChartView alloc] init]; [timeLineChartView setFrame:self.view.frame]; ...
使用者介面-漂亮的MPAndroidChart的iOS端口 -UITableView的显示器-在iMessage应用程序中显示诸如时间戳之类的隐藏视图。 扁平进度条视图,替代UIProgressView 一个UILabel子类,该子类将文本弯曲成圆弧:-) 适用于iOS...
8.5.2 向表视图单元添加子视图 156 8.5.3 使用UITableViewCell的自定义子类 159 8.6 分组分区和索引分区 163 8.6.1 构建视图 163 8.6.2 导入数据 164 8.6.3 实现控制器 164 8.6.4 添加索引 168 8.7 实现搜索栏 168 ...
索引/首页: 选择下拉操作按钮以查看接口badnwidth或接口详细信息(接口的CLI视图。)<-Cisco IOS-XE 实时图表->(需要浏览器弹出窗口): 所有数据应反映正数。 如果返回-1,则表示计算错误 如果图形显示为“ ...
一个自字定义的环形转圈,并自动计时,的动画效果,也...比传统的,手动滑动索引,更吸引用用户使用!可以滑动,也可自动进行计时,也可以在最上面的scroller上面的每一页,加自己想要的动画,具体请参考“赤兔”app