IOS开发(26)之UITableView的页眉和页脚
来源:互联网 发布:软件配置文件用途 编辑:程序博客网 时间:2024/06/05 16:36
1 前言
UITableView中的每个Section中都可以设置页眉和页脚,来满足需求。用户都可以自己设置。
2 代码实例
ZYViewHeaderFooterController.h:
#import <UIKit/UIKit.h>@interface ZYViewHeaderFooterController : UIViewController<UITableViewDelegate,UITableViewDataSource>//添加代理@property(nonatomic,strong) UITableView *myTableView;@end
ZYViewHeaderFooterController.m:
@synthesize myTableView;- (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, typically from a nib. self.view.backgroundColor = [UIColor whiteColor]; myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];//设置列表样式为简单的样式 还有一个样式为UITableViewStyleGrouped为分组模式 UITableViewStylePlain为普通的样式 self.myTableView.delegate = self;//设置代理为自身 myTableView.dataSource = self;//设置数据源为自身 self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;//确保TablView能够正确的调整大小 [self.view addSubview:myTableView];}//设置每个Section呈现多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 3;}//每行像是的数据-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *result = nil; if ([tableView isEqual:myTableView]) { static NSString *tableViewCellIdentifier = @"MyCells";//设置Cell标识 result = [tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifier];//通过标示符返回一个可重用的表视图单元格对象 if (result == nil) { result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCellIdentifier];//初始化一个表格单元格样式和重用的标识符,并将它返回给调用者。 } //indexPath.section 表示section的索引 indexPath.row表示行数的索引 result.textLabel.text = [NSString stringWithFormat:@"Section %ld,Cell %ld",(long)indexPath.section,(long)indexPath.row]; } return result;}//设置Section的Header-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ NSString *result = nil; if ([tableView isEqual:myTableView]&§ion==0) { result = @"Section 0 Header"; } return result;}//设置Section的Footer-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ NSString *result = nil; if ([tableView isEqual:myTableView]&§ion==0) { result = @"Section 0 Header"; } return result;}
运行结果:
3 结语
以上就是所有内容,希望对大家有所帮助。
Demo实例:http://download.csdn.net/detail/u010013695/5321657
- IOS开发(26)之UITableView的页眉和页脚
- IOS学习笔记(10)UITableView展示数据 cell删除 构建页眉页脚
- IOS开发(28)UITableView之移动Section和Cell
- iOS开发之UITableView的两种类型(plain和group)
- IOS开发(25)之删除UITableView的Cell
- iOS开发之UITableView的性能优化
- iOS开发笔记之UITableView的使用
- IOS 开发之UITableview的基本创建
- iOS开发之UITableView的使用
- IOS开发(23)之UITableView控件
- iOS开发之UITableView(一)
- 页边距和页眉页脚的设置
- 设置tableView的页眉和页脚
- iOS之UITableView和NSTableView的区别
- IOS 构造和使用TableView(基于storyboard) (五)构建页眉和页脚
- iOS开发 UITableView之cell
- iOS开发学习之UITableView
- 4、iOS 开发之 UITableView
- Oracle初体验
- Struts2框架简单的AJAX应用
- iText学习资料
- 第三方评论系统
- 认识保护模式之汇编复习2
- IOS开发(26)之UITableView的页眉和页脚
- mysql字符串
- SAP HANA 字符函数(二) (SAP HANA String Functions)
- 【重庆邮电大学俱乐部】CSDN会员总结报告汇集
- OpenCV的IplImage图像格式
- ZOJ 2111 Starship Troopers(树形DP)
- 在CentOS系统上静默安装Oracle 11gR2
- android4.0 开启硬件加速后应用运行出错
- Java标识符使用规范