IOS编程 之 UITableView

表视图:

表视图继承自UIScrollView,所以可以滚动
表视图的每一条数据都是显示在UITableViewCell对象中

表视图可以分区显示数据,每个分区称为一个section,每一行称为row,编号都是从0开始


重要的属性:

style样式: plain 和group

分割线样式:separatorStyle

分割线颜色:separatorColor

行高:rowHeight


两个必须实现的方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;


表视图的重用机制






- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSLog(@"%s",__func__);

    

    static NSString *cellIdentify = @"cellIdentify";

    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];

    //cellIdentify命名的重用池中取得cell

    if (!cell) {

        //如果不存在 创建一个cell 并且将他放到以cellIdentify命名的重用池里面 方便下次使用

        cell = [[[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify]autorelease];

    }

    NSLog(@"section === %d row === %d",indexPath.section,indexPath.row);

    NSString *str = [_tableArray objectAtIndex:indexPath.row];

    [cell.textLabel setText:str];

    

    return cell ;

    

}






指定哪一行可以移动

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;


指定tableView编辑的样式 (添加,删除)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowIndexPath:(NSIndexPath *)indexPath;


关于表视图的移动:

首先让tableView处于编辑状态,方法如上;

指定哪些tableView可以移动:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

完成移动

- (void)tableView :(UITableView *)tableView moveRowAtIndexPath :(NSIndexPath *)destinationIndexPath;

监测移动过程 实现限制跨区移动


UITableViewController

继承UITableView 自带一个tableView 根视图就是tableView

模板自带编辑移动的相关代码





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值