Evans.Y Evans.Y - 11 months ago 57
iOS Question

Why the UITableViewCell changed its size when I slide the view

enter image description hereeveryone,I am a beginner in iOS development.
Now I face a problem:I wrote a small program to learn custom UITableViewCell. It just can work well at the beginning. When I slide the view, it will change. I feel really confuse.
And the ContentView only has one view which is 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;
}


This is the picture, top two are good,but when I slide down, as you can see, the 3rd doesn't work well

Answer
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HWHomePageCell"];

        cell = [HWHomePageCell homePageCell];

        cell.imageView.image = [UIImage imageNamed:@"XD"];

    return cell;
}

When you use custom cell then no need to check whether cell is nil or not. so please remove this condition and implement it.