How can I create a variable sized UITableViewCell?

狂风中的少年 提交于 2019-12-02 16:52:53
notnoop

Tweetero provides an example of this in MessageListController.m. The code there renders the following screen:

(Pic is taken from Mashable).

The basic implementation outline:

  1. When constructing a UITableViewCell, create and add a UILabel as a subview in the manner shown in tableviewCellWithReuseIdentifier:. Look for the creation of TEXT_TAG label.

  2. when enriching the UITableViewCell with views, ensure that you format label properly, as is done in configureCell:forIndexPath, similarly look for the label tag TEXT_TAG.

  3. Return the appropriate height for each cell, as is done in tableView:heightForRowAtIndexPath.

myLabel.numberOfLines = 2;

Check the docs for full info on how to use this property.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return theSizeYouWantYourCellToBe;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!