读书人

避免UITableViewCell重叠的解决办法

发布时间: 2013-07-04 11:45:40 作者: rapoo

避免UITableViewCell重叠的解决方法

在IOS开发的时候经常会用到UITableView,而当TableView进行拖动的时候经常会导致Cell的重叠,解决方法,

1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    static NSString *CellIdentifier = @"ToneBoxMusicStyleViewCell";        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];        if (cell == nil) {        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"ToneBoxMusicStyleViewCell" owner:self options:nil];                if ([nib count] > 0) {            cell = self.styleViewCell;        }    }else{        for (UIView *subView in cell.contentView.subviews)        {            [subView removeFromSuperview];        }    }    return cell;}

?

?

2

//构建tableView-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@"TodoViewController"];    cell.tag = 1;    if(!cell){        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"TodoViewController"]autorelease];                    }else{        while ([cell.contentView.subviews lastObject] != nil) {            [(UIView *)[cell.contentView.subviews lastObject] removeFromSuperview];        }    }

?

读书人网 >移动开发

热点推荐