iOS8 UITableViewCell rowheight仅在第一次不正确

时间:2015-01-07 09:36:16

标签: uitableview ios8

这是cellForRowAtIndex代码

static NSString *ClipCellIdentifier = @"HomeClipCell";

        HomeClipCell *clipCell = [tableView dequeueReusableCellWithIdentifier:ClipCellIdentifier];

        [clipCell setUSeparatorStyle:SeparatorStyle_Top];
        if (indexPath.section==2) {
            [clipCell setClipInfoArray:_clipsArray];
            [clipCell setClickBlock:^(NSInteger index) {
                VodInfo *vodInfo = weakSelf.clipsArray[index];

                VideoDetailViewController *detailView = [weakSelf viewControllerWithIdentifier:@"VideoDetailViewController"];

                [detailView setVodInfo:vodInfo];
                [detailView setRootViewController:weakSelf.rootViewController];

                [weakSelf.navigationController pushViewController:detailView animated:YES];
            }];
        }else {
            [clipCell setClipInfoArray:_mostPopArray];
            [clipCell setClickBlock:^(NSInteger index) {
                VodInfo *vodInfo = weakSelf.mostPopArray[index];

                VideoDetailViewController *detailView = [weakSelf viewControllerWithIdentifier:@"VideoDetailViewController"];

                [detailView setVodInfo:vodInfo];
                [detailView setRootViewController:weakSelf.rootViewController];

                [weakSelf.navigationController pushViewController:detailView animated:YES];
            }];

        }

        [clipCell setNeedsUpdateConstraints];
        [clipCell updateConstraintsIfNeeded];

        return clipCell;

非常奇怪。第2节中的单元格显示得非常好。但在其他情况下,单元格高度在第一次显示为44.第二次(滚动tableView),它显示正确。

我还从dequeueReusableCellWithIdentifier中找到了cell:size是不同的。在第2节的情况下,单元格高度是正确的大小,但其他高度是44。

有人可以帮帮我吗?感谢。

*添加信息*

这只发生在我的iPhone5s上。在iPhone6模拟器中它也能很好地显示。

1 个答案:

答案 0 :(得分:0)

行高是非负的并以点表示。如果委托没有实现tableView:heightForRowAtIndexPath:方法,则可以为单元格设置行高。如果未明确设置行高,UITableView会将其设置为标准值。

使用tableView:heightForRowAtIndexPath:而不是rowHeight会对性能产生影响。每次显示表视图时,它会在每个行的委托上调用tableView:heightForRowAtIndexPath:这会导致表视图具有大量行(大约1000或更多)的显着性能问题。

来自Apple docs

尝试实现此方法,也许它会解决问题

相关问题