Using different reuse identifiers for the same user cell

Im following the concept mentioned in https://stackoverflow.com/a/167129/127/... but in a slightly different way to implement a dynamic cell using auto layout. I have only one user cell prototype. But I have to add some UILabel elements to the cell based on the data array and maintain the dynamic height of the cell.

// My UITableViewCell

@interface CustomCell ()
@property (nonatomic, assign) BOOL didAddLabel;
@end
@implementation CustomCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

-(void)addLabel:(NSArray*)someAry{

    if(!didAddLabel){

        for (int i=0; i<someAry.count; i++) {

            // Initialize UILabel Programtically ...
            // adding label
            [self.aViewOfContaintView addSubview:aLabel];
        }


        self.heightLayoutConstraintOfaViewOfContaintView.constant = value;
        [self.aViewOfContaintView layoutIfNeeded];

        self.didAddLabel = YES;
    }
}
@end

// My UIViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    //.. .. ..
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 100;
    //.. .. ..
}

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


    CustomCell *cell = (CustomCell *)[theTableView dequeueReusableCellWithIdentifier:CellIdentifier];



    // Configure the cell for this indexPath
    //.. .. ..

    //Add Label
    [cell addLabel:anAry];

    [cell layoutIfNeeded];
    return cell;
}

if I do not use this didAddLabel check then scroll the table. If I use this, then only I get four cells with different heights.

" ..."

/ ? .

+4
1

:

/nibs /nib . dequeue

-1

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


All Articles