1. 首先是先创建UITableView
/*
UITableViewStylePlain
UITableViewStyleGrouped 分组
*/
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
2. 需要遵守协议UITableViewDataSource, UITableViewDelegate
self.tableView.dataSource = self;
self.tableView.delegate = self;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
return cell;
}
本文详述了如何在iOS应用中创建一个分组样式UITableView,包括初始化表格视图、遵守DataSource和Delegate协议,以及关键的numberOfRowsInSection和cellForRowAtIndexPath方法实现。重点讲解了单元格的动态创建和复用技巧。
3048

被折叠的 条评论
为什么被折叠?



