How can I create a variable sized UITableViewCell?

前端 未结 3 1007
萌比男神i
萌比男神i 2021-01-31 06:22

I can\'t seem to get the text to actually span multiple lines. The heights look correct. What am I missing?

- (UITableViewCell *)tableView:(UITableView *)tableVi         


        
相关标签:
3条回答
  • 2021-01-31 06:57

    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.

    0 讨论(0)
  • 2021-01-31 07:06
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return theSizeYouWantYourCellToBe;
    }
    
    0 讨论(0)
  • 2021-01-31 07:10
    myLabel.numberOfLines = 2;
    

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

    0 讨论(0)
提交回复
热议问题