UITableView 遇到的小或大的问题

 

问题 1 :

cell中放置标签后,上下滑动tableView,标签上的文本重叠。

 

解决办法:

把标签remove掉


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

    staticNSString*CellIdentifier =@"Cell";

    UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell ==nil) {

        cell= [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault

                                      reuseIdentifier:CellIdentifier] autorelease];

       

    }

        for (UIView *a in cell.contentView.subviews)

        {

            if([a isKindOfClass:[UILabel class]])

           {

               [a removeFromSuperview];

           }

        }

       ...

}



问题 2 :

多个section 结构不一样时,tableview显示混乱

解决办法:

对每个section,分别重用cell


if (indexPath.section ==0)

    {

        static NSString *CellIdentifier =@"Cell0";

       

        UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

        if(cell ==nil) {

           cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault

                                          reuseIdentifier:CellIdentifier]autorelease];

           

        }

 

 

 

return cell;

}

elseif(indexPath.section == 1)

    {

        static NSString*CellIdentifier =@"Cell1";

       

        UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

        if(cell ==nil) {

           cell = [[[UITableViewCellallocinitWithStyle:UITableViewCellStyleDefault

                                          reuseIdentifier:CellIdentifier]autorelease];

           

        }

 

 

 

 

return cell;

}



问题 3:

有三个结果一样的section ,每行row分别定义

if (indexPath.row ==0)

    {

           ...
      cell.textLabel.text =string1;

  

    }

    elseif(indexPath.row == 1)

    {

                ...

        cell.textLabel.text =sring2;

          }

    else if(indexPath.row == 2)

    {

        cell.textLabel.text =@"";

        UILabel *label2 = [[UILabelalloc]initWithFrame:CGRectMake(10,20,100,40)];

        label2.text =@"餐桌人员:";

        label2.tag =98;

        //label1.font = [UIFont systemFontOfSize:18];

        UILabel *label22 = [[UILabelalloc]initWithFrame:CGRectMake(110,10,180,60)];

        label22.text = [[[[dicobjectForKey:@"result"]objectForKey:@"deskList"]objectAtIndex:indexPath.section]objectForKey:@"members"];

        label22.tag =99;

        label22.numberOfLines =0;

 

        label2.backgroundColor = [UIColorclearColor];

        label22.backgroundColor = [UIColorclearColor];

       

        [cell.contentViewaddSubview:label2];

        [cell.contentViewaddSubview:label22];

      

    }

运行后,发现上下滑动tableview后,数据串变,不在指定的row显示指定的内容


解决办法:

if(indexPath.row ==2)

中加上   cell.textLabel.text =@"";

indexPath.row ==2时,重用的cell还留有上一次的cell.textLabel.text内容,没有对其更新的话可能会覆盖掉加上去的label




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值