Snail—UI学习之UITableView之分组显示
来源:互联网 发布:矩阵分配律 编辑:程序博客网 时间:2024/05/01 10:21
之前的demo都是一个分组显示数据的
这次我们用的是带有分组的tableView
#import "WJJRootViewController.h"@interface WJJRootViewController (){ UITableView * _tableView; NSMutableArray * _dataArray;}@end@implementation WJJRootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view. [self createDataSource];}- (void)createDataSource{ _dataArray = [[NSMutableArray alloc] init]; //先把工程下 所有的plist路径获取到 装到数组里面 NSArray * plistPath = [[NSBundle mainBundle] pathsForResourcesOfType:@"plist" inDirectory:@""]; //遍历这个数组 把系统的plist剔除 for (NSString * pathString in plistPath) { //如果这个路径 是系统的plist路径 略过 if ([pathString hasSuffix:@"Info.plist"]) { continue; } NSArray * plistArray = [[NSArray alloc] initWithContentsOfFile:pathString]; [_dataArray addObject:plistArray]; } [self createTableView];}- (void)createTableView{ //tableView的风格是分组的 _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; //设置代理和数据源代理 _tableView.delegate = self; _tableView.dataSource = self; [self.view addSubview:_tableView]; }#pragma mark --UITableViewDelegate--//tableView是分组类型的 先设置组的个数- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return _dataArray.count;}//设置每组有多少行- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ //返回数据源里 与 section相对应的 数组的元素个数 return [[_dataArray objectAtIndex:section] count];}//cell的代理方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell * cell = [_tableView dequeueReusableCellWithIdentifier:@"ID"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"]; } NSDictionary * dict = [_dataArray[indexPath.section] objectAtIndex:indexPath.row]; [cell.imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",[dict objectForKey:@"imageName"]]]]; [cell.textLabel setText:[NSString stringWithFormat:@"%@",[dict objectForKey:@"imageInfo"]]]; [cell.detailTextLabel setText:[NSString stringWithFormat:@"%@",[dict objectForKey:@"imageInfo"]]]; return cell;}//设置头标题- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ //这里的数据是我们自己写的 NSArray * titleArray = @[@"圣斗士",@"海贼王",@"火影忍者",@"妹子们"]; return titleArray[section];}//设置索引- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return @[@"圣",@"海",@"火",@"妹"];}//返回行标题的高度- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 25;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];}//返回行的高度- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 70;}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- Snail—UI学习之UITableView之分组显示
- Snail—UI学习之UITableView之自定义UITableViewCell
- Snail—UI学习之初识
- Snail—UI学习之UILabel
- Snail—UI学习之UIButton
- Snail—UI学习之动画Animations
- Snail—UI学习之UITextField
- Snail—UI学习之进度条UIProgressView
- Snail—UI学习之UISegmentControl
- Snail—UI学习之开关UISwith
- Snail—UI学习之工具栏UIToolBar
- Snail—UI学习之得到某组件的方法
- Snail—UI学习之UIImage及UIImageView
- Snail—UI学习之自定义通知NSNotification
- Snail—UI学习之导航视图控制器UINavigationController(系统)
- Snail—UI学习之自定义导航栏NSNavigationController
- Snail—UI学习之代理传值Delegate
- Snail—UI学习之滑块UISlider
- 【读书笔记】iOS-UIFont-动态下载系统提供的字体-官方代码
- mongoDB修改key里面的key的value
- 润叶在他最低沉的时候是谁在他的身边
- Z-WIFI+openWRT
- AOP 那点事儿
- Snail—UI学习之UITableView之分组显示
- OC学习@property和@synthesize的使用
- hdu杭电1789 Doing Homework again【优先队列+贪心】
- ArrayList集合的简单使用
- 明川和治功现在正说牛家沟那个“母老虎”的事
- Redis安装和简单测试
- GVim一些常用快捷键
- scala actor swing代码实践
- Android 代码混淆 选项说明