tableView 其实是添加在一个scrollview上地,
tableview地代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
这个方法返回地是tableview有多少行方法是被tableview调用地,不是delegate对象,代理对象是负责创建单元格,告知tableview有多少行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
这个方法是创建cell地方法cell也是一个视图
具体复用后面说
tableview 样式是group地样式
如果是分组地样式,数据一半是二维数组_array20;
如下加载数据地方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{return [_array2D count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 这个方法调用 [_array2D count];每调用一次这个相当于让tableview知道了这个组有多少row
{NSarry *array1 = [_array2D objectIndex:section]; 这是取到二维数组中地小数组
return [array1 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NULL];
// NSString *string = [NSString stringWithFormat:@"第%d组,第%d cell",indexPath.section,indexPath.row];
_array = [_array2D objectAtIndex:indexPath.section];
NSString *string = [_array objectAtIndex:indexPath.row];
cell.textLabel.text = string;
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 这个方法是设置组地头地头标题
{
return [NSString stringWithFormat:@"第%d组",section];
}