xcode - iOS tableView cell复用出错问题
阿神
阿神 2017-04-17 17:52:45
[iOS讨论组]

部分代码如下,点击后,刷新cell都出错,复用出了问题,请问要怎么设置复用,如何避免这样的问题

static NSString * const defealtSelectCellID = @"applyTransferEstSelectItemCell";

[_tableView registerNib:[UINib nibWithNibName:@"ApplyTransferEstSelectItemCell" bundle:nil]
         forCellReuseIdentifier:defealtSelectCellID];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:{

            ApplyTransferEstSelectItemCell *cell = [tableView dequeueReusableCellWithIdentifier:defealtSelectCellID forIndexPath:indexPath];
            
            if (_propertyFollowAllAddEntity.TrustorTypeKeyId) {
                cell.rightValueLabel.text = _propertyFollowAllAddEntity.TrustorTypeKeyId;
            }else{
                [cell setupLeftTitleWithString:@"*联系人类型" rightLabelString:@"请选择联系人类型"];
            }
            
            return cell;
        }
case 2:{

            ApplyTransferEstSelectItemCell *cell = [tableView dequeueReusableCellWithIdentifier:defealtSelectCellID forIndexPath:indexPath];
            
            
            if (_propertyFollowAllAddEntity.TrustorGenderKeyId) {
                cell.rightValueLabel.text = _propertyFollowAllAddEntity.TrustorGenderKeyId;
            }else{
                [cell setupLeftTitleWithString:@"*性别" rightLabelString:@"请选择联系人性别"];
            }
            
            
            return cell;
        }

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    _selectedIndexPath = indexPath;
    
    switch (indexPath.row) {
        case 0:{            
                NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:reloadIndexPath]
                                          withRowAnimation:UITableViewRowAnimationNone];
                
            }];
            break;
            
        }
        case 2:{
                NSIndexPath *reloadIndexPath = [NSIndexPath indexPathForRow:2 inSection:0];
                [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:reloadIndexPath]
                                          withRowAnimation:UITableViewRowAnimationNone];
                
            }];
            break;
            
        }
阿神
阿神

闭关修行中......

全部回复(2)
怪我咯

要考虑从复用队列找不到cell的情况

阿神

结合cell缓冲池和prepareForReuse方法,可参考博客http://serazheng.github.io/2015-08-15-%E...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号