UITableView注意点

一.当自定义了cell(假如名字为myCell),在控制器中想调用这个cell中的某个属性(假如为name)时,不可直接用myCell.name,这样调用会发现myCell.name中为空,实际代码应该为:

NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];//假如这个cell在tableView中为第0个分区的第一行(没有分区时即为0分区)
    myCell *cell = [tableView cellForRowAtIndexPath:indexPath];
 再调用cell.name即可了

二.当在footVIew或者headerView中需要根据请求的连接来创建一些label或者button的,即根据连接的请求需要即时刷新footVIew或者headerView,则此时定义footVIew或者headerView时不可用
UILabel *headerLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
headerLabel.text = @"这里是表头";
_tableView.tableHeaderView = headerLabel;

这种方法。而应该用

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *header = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];

    return header;
}

并注意不要忘了
//自定义高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;
}

三.grpup形式的tableView是有组尾的,要想让其消失代码应为:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{

        return 0.00000001;//注意不应该返回0
}

另注:tableView中某些情况下,需要将组头或者组尾隐藏掉时,除了隐藏的代码外,还应该将组头或者组尾的返回高度设置为return 0.00000001;不是返回为0

四.获取指定的cell

//获取第0个分区的第1个cell
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];
            ShopAnalysisType1Cell *cell = [_shopAnalysisTable cellForRowAtIndexPath:indexPath];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值