tableView 重叠解决方法

来源:互联网 发布:人生规划 书籍 知乎 编辑:程序博客网 时间:2024/06/04 19:51

借鉴很多文章,但并没侵权


在创建时

 1、UITableViewCell *cell =nil;

2、删除

 2.1、UITableViewCell *cell = nil;

   if (cell ==nil) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellId];

    }

    else{

        while ([cell.contentView.subviews lastObject] !=nil) {

            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview]; //删除并进行重新分配

        }

    }

另一种方法

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *cellIdetify = @"cell";    UITableViewCell *tvCell = [tableView dequeueReusableCellWithIdentifier:cellIdetify];        if(tvCell == nil)    {        NSLog(@"cell = nil");        tvCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdetify] autorelease];    }else{        NSLog(@"cell !=nil ");        NSArray *views = [tvCell subviews];        for (UIView *obj in views) {            if (obj.tag==1000 || obj.tag==2000) {      //只删除指定的画面,不要全部删除,否则tableview的分割线也会被删除                NSLog(@"cell 要删除的子画面是:%@",[obj class]);                [obj removeFromSuperview];            }        }
3、标识符:NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];//以indexPath来唯一确定cell 

4、 staticNSString *cellId =@"couponviewController";

    UITableViewCell *cell = [tableViewcellForRowAtIndexPath:indexPath];


0 0
原创粉丝点击