首页 > 其他 > 详细

UITableView中防止cell内容拖动后重叠

时间:2014-11-29 20:19:20      阅读:312      评论:0      收藏:0      [点我收藏+]

由于cell是高效复用的,每当拖动后,在cell.contentView,这些个view就会重叠,网上找了些方法,结合自己的代码,记录下来。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//这里的reuse,是cell的Identifier
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];;
    
    if (!cell) {
       //在 cell中增加需要的内容
       cell add things
    }
    else {
    //移除原来的子视图
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];}
    }
    //在 cell中增加需要的内容
    cell add things
    return cell;
}


UITableView中防止cell内容拖动后重叠

原文:http://my.oschina.net/u/2262643/blog/350343

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!