search

Home  >  Q&A  >  body text

ios - UITableView下拉后cell位置改变

大家好,我是一iOS新手,目前遇到一个很奇怪的问题:
我写了一个小程序想学下自定义UITableViewCell,自定义的contentView中只有一个ImageView,然后一开始显示正常,但是当我下拉后,cell就改变了位置,这是为什么

前两个图是正常初始化出来的,后一个是下拉后刷新出来的。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWHomePageCell"];
    if (cell == nil)
    {
        cell = [HWHomePageCell homePageCell];
    }
        cell.imageView.image = [UIImage imageNamed:@"Test"];
    
    return cell;
}

我觉得是代码重用这里的问题,但是我尝试了各种设置,都没有用。。。求大神赐教

PHP中文网PHP中文网2889 days ago328

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-18 09:07:40

    cell = [HWHomePageCell homePageCell]
    Have you written the correct ID in this initialization method honmePageCell?
    Also try writing the ID of the cell on the storyBoard

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:07:40

    Try writing the coordinates of a custom cell in the layoutSubView method

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:07:40

    Finally, I deleted the conditional judgment of if (cell == nil), and the result was just fine.
    Sincere thanks to everyone above for your enthusiastic help!

    reply
    0
  • Cancelreply