IOS source code UITableViewCell

I have UITableViewCellcreated with help .xibthat uses cell autococialization. In iOS 9, it works well, but in iOS 8, the cell does not expand, and 1 line of text remains inside the label. If the cell leaves the screen and returns (i.e., after scrolling), all the shortcuts are in order.

Ideas? I think this is an iOS 8 bug.

enter image description here enter image description here

+4
source share
3 answers

I had the same problem. If your restrictions are set correctly, you need to set preferredMaxLayoutWidthfor each UILabelthat you have in the cell, just before the cell returns. Here is a sample code

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.lblTitle.text = @"N";
    cell.lblDetails.text = @"bla bla";
    cell.lblOther.text = @"other text";


    // Configure the cell...
    CGfloat leftPading =// "your logo width + spacing between logo and label"
    CGfloat rightPading = //your label trailing space
    cell.lblTitle.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)-(leftPading +rightPading);
    cell.lblDetails.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)-(leftPading +rightPading);
     [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];

    return cell;
    }

, ,

, .

+3

,

1. Define auto layout constraints for your prototype cell
2. Specify the estimatedRowHeight of your table view
3. Set the rowHeight of your table view to UITableViewAutomaticDimension

http://www.appcoda.com/self-sizing-cells/

edit: , , , , swift obj-c ( ). , - ( )... .

-1

.

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

. - , .

-1

Source: https://habr.com/ru/post/1627767/


All Articles