TableView

来源:互联网 发布:卖精仿鞋的淘宝店铺 编辑:程序博客网 时间:2024/05/17 01:34

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 = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:NULL];

    

//    NSString *string = [NSString stringWithFormat:@"%d组,第%d cell",indexPath.section,indexPath.row];

   _array = [_array2DobjectAtIndex:indexPath.section];

    NSString *string = [_arrayobjectAtIndex:indexPath.row];

    

    cell.textLabel.text = string;

    return cell;

    

    

}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  这个方法是设置组地头地头标题

{

    return [NSStringstringWithFormat:@"%d",section];


    

}











0 0