码迷,mamicode.com
首页 > 其他好文 > 详细

tableview cell 的重复添加

时间:2016-07-05 20:32:27      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

当有两种cell的时候,发生了如下神奇事件:

技术分享

 

原因:

技术分享

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UserInfoCell *Cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_UserInfoCell forIndexPath:indexPath];
    
    PDOptionCell *optionCell = [tableView dequeueReusableCellWithIdentifier:optionCellId forIndexPath:indexPath];
    
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
                [Cell setUserInfoWithImage:@"Mine_rec_name" Title:@"真实姓名" Info:_login_User.cur_User.realname];
                return Cell;
                break;
            case 1:
                [Cell setUserInfoWithImage:@"Mine_rec_num" Title:@"身份证号码" Info:_login_User.cur_User.id_card];
                return Cell;
                break;
            case 2:
            {
//                NSIndexPath *index = [NSIndexPath indexPathForRow:2 inSection:0];
                [optionCell reconstructSubviewsUnderMode:OptionCellModePic];
//                [self.myTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationAutomatic];
                return optionCell;
            }
                break;
        }

 

调用了 

dequeueReusableCellWithIdentifier:   forIndexPath:

在重用机制里,这个方法会重复调用两次

导致重用出现错乱,在只有一种cell的时候,察觉不到这样的情况,

但是一旦有多种cell,一定导致重用出错!

 

于是解决办法:换用 

dequeueReusableCellWithIdentifier:

方法

 

结果如下:

技术分享

 

技术分享

 

tableview cell 的重复添加

标签:

原文地址:http://www.cnblogs.com/DanteBarnett/p/5644786.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!