我是iOS开发的初学者。我遇到了一个几乎不需要帮助的问题。
我写了一个小程序来学习自定义UITableViewCell。刚开始时效果很好;之后,当我滑动 View 时,它会改变单元格的大小。我很困惑我可能哪里出错了。 ContentView 只有一个 View ,即 UIImageView。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWHomePageCell"];
if (cell == nil)
{
cell = [HWHomePageCell homePageCell];
}
cell.imageView.image = [UIImage imageNamed:@"XD"];
return cell;
}
最佳答案
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWHomePageCell"];
cell = [HWHomePageCell homePageCell];
cell.imageView.image = [UIImage imageNamed:@"XD"];
return cell;
}
当您使用自定义单元格时,无需检查单元格是否为零。所以请删除这个条件并执行它。
关于ios - 为什么当我滑动 View 时 UITableViewCell 改变了大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37537997/