How to make UITableViewCell display fullscreen (al

2020-07-27 05:27发布

问题:

I have a custom UITableView - Scroll, Paging Enable. Because each of my cell has one background image, I want each time I scroll up or down it will display each image as full screen. I try to make my UITableViewCell to be full screen (stretch its height as big as the tableview).

However, I've got a problem: when I scroll(paging), the cell doesn't display as full screen. It contains a small part of the next cell. Then the part of next cell increase bigger and bigger each time I scroll(paging) down.

I didn't see any Auto Layout Option for UITableViewCell, cannot add constraint to the prototype cell. Would you please suggest me the way to do it? Thank you very much.

回答1:

i just add this two lines of code and it works for me

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return tableView.frame.size.height;
}


回答2:

// ***** The following SWIFT function expands the cell image view to full screen (frame.size.height), adding to M.Salah's reply above.

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return tableView.frame.size.height;
}