表的组头尾视图的自定义
来源:互联网 发布:淘宝运营商 编辑:程序博客网 时间:2024/05/16 07:59
AppDelegate设置根视图控制器
RootViewController.h
@interface RootViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{ NSArray *_data;}
RootViewController.m
- (void)viewDidLoad{ [super viewDidLoad]; //创建表视图 UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460) style:UITableViewStyleGrouped]; tableView.dataSource = self; tableView.delegate = self; [self.view addSubview:tableView]; [tableView release]; <span style="color:#ff0000;">//读取本地的数据</span> NSString *path = [[NSBundle mainBundle] pathForResource:@"font" ofType:@"plist"]; _data = [[NSArray alloc] initWithContentsOfFile:path]; }#pragma mark - UITableView dataSource//指定组的个数- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return _data.count;}//指定相应组的cell个数- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *arrary2D = [_data objectAtIndex:section]; return arrary2D.count;}//创建单元格cell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; NSArray *arrary2D = [_data objectAtIndex:indexPath.section]; NSString *str = [arrary2D objectAtIndex:indexPath.row]; cell.textLabel.text = str; cell.textLabel.font = [UIFont fontWithName:str size:17]; return [cell autorelease]; }#pragma mark - UITableViewDelegate//单元格被选中后调用的方法- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%d组%d行的单元格被选中了",indexPath.section,indexPath.row); <span style="color:#ff0000;">//取消选中效果</span> [tableView deselectRowAtIndexPath:indexPath animated:YES];}/* 下面这个方法 *///给组的头视图设置标题- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ NSString *str = [NSString stringWithFormat:@"头视图的标题:%d组的标题",section]; return str;}//给组的尾视图设置标题- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { NSString *str = [NSString stringWithFormat:@"尾视图的标题:%d组的标题",section]; return str; }//自定义组的头视图和尾视图- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ <span style="background-color: rgb(255, 0, 0);"> //headerView的frame值设置没有效果</span> //CGRectMake(0, 0, 0, 0)等价于CGRectZero UIView *headerView = [[[UIView alloc] initWithFrame:CGRectZero]autorelease]; headerView.backgroundColor = [UIColor redColor]; UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 10, 180, 20)]autorelease]; label.text = [NSString stringWithFormat:@"尾视图的标题:%d组的标题",section]; label.textColor = [UIColor greenColor]; label.font = [UIFont systemFontOfSize:15]; [headerView addSubview:label]; return headerView;}//设置组的头视图的高度//或者 tableView.sectionHeaderHeight- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 50;}
0 0
- 表的组头尾视图的自定义
- 强大的分组SectionListView, 支持自定义组头布局和分组的内容布局, 组头有挤压效果
- 强大的分组SectionListView, 支持自定义组头布局和分组的内容布局, 组头有挤压效果
- UICollectioView的组头和组尾的高度不同设置
- iOS 开发 解决UICollectionView的多组头部视图样式不一样复用时发生错乱问题
- UITableView的表头表尾(tableHeaderView,tableFooterView) 和 组头组尾(viewForHeaderInSection,heightForFooterInSec
- Xamarin 设置ListView组头的高度
- ListView演练 - 带有组头的汽车品牌展示
- 自定义视图的绘制
- 自定义的照相机视图
- 自定义UICollectionView的头视图或者尾视图(UICollectionReusableView)
- 自定义View-仿微信群组头像
- 自定义视图:视图的封装过程.
- 自定义视图,视图控制器的使用
- LongListSelector 锁定组头(sticky header )之我的实现
- android 群组头像的显示(仿QQ群组)
- UITableView去掉Grouped样式的第一组Header组头
- android 群组头像的显示(仿QQ群组)
- 好肥啊共和国认同和个人头还不要停
- 管理Sass项目文件结构
- OC语法总结
- 剖析Apple Pay 它与支付宝究竟暧昧什么?
- jsp中<base target='' />标签用法
- 表的组头尾视图的自定义
- eclipse删除无用的workspace工作空间记录,启动eclipse时提示选择workspace
- STM32F30X SYSTICK做非精确的delay功能
- 作为一个屌丝程序员不得不收藏的工具类 一 网站爬虫工具类
- Java Annotation 注解基础原理简析
- 关于 war 包打开的问题
- 贪吃蛇
- 如何在IIS下建站
- Android 禁用和开启四大组件之setComponentEnabledSetting方法