简体   繁体   中英

Height of UItableViewCell Issue

I use UITableView to show some message, and the cells have different height. It works well before we upgrade the project to swift3 .

Issue :

If I run same project in iOS 8.1 , the UITableView will show with the wrong height 44(default cell height).

I test that the UITableView will call

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 

method every time before -viewDidAppear and after -viewWillAppear

method, to calculate the height of every first cell in the session.

Output : Printed Height Output Here

Test with iOS 9.3 , it never call the method after the UITableView was first loaded.

I think it is the reason why give me the wrong height, but why it calls?

Implement this UITableViewDelegate methods :

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

and

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
{
    return UITableViewAutomaticDimension
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM