ios - 为什么当我滑动 View 时 UITableViewCell 改变了大小

标签 ios objective-c uitableview

我是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;
}

These are the pictures. Top two are good, but when I slide down, as you can see, the 3rd doesn't work well

enter image description here

最佳答案

  - (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/

相关文章:

ios - 从 AppDelegate 加载 Storyboard 在窗口上留下黑色空间

ios - 从另一个 anchor 在背景中缩放动画

ios - 如何在 Objective-C 中找到路由器 IP 地址?

ios - 当表格 View 被多重选择时,使用自定义图像替换复选标记

ios - prepareForSegue :sender: gets wrong sender

ios - 尝试使用元组保存时出现核心数据错误

ios - 视频方向纵向模式不起作用

ios - 每月更新 NSUserDefaults 值

ios - 更改 iOS 应用程序的默认语言环境

iphone - 如何知道 UITableView 中 Tableview 单元格的按钮单击部分编号?