Frame is not changing in cellForRowAtIndexPath

I want to change the x position frame of view inside the cell in cellForRowAtIndexPath for certain conditions. I have used the following code. But it does not change the view’s x position frame.

- (void)viewDidLoad {
    [super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"GoalDetailsCustomCardCell" bundle:nil];

        [goalDetailsTableView registerNib:nib forCellReuseIdentifier:@"CardCell"];
}
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        GoalDetailsTableViewCell *cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];

        if(cell == nil)
        {
            cell = [goalDetailsTableView dequeueReusableCellWithIdentifier:@"CardCell"];
        }

    NSLog(@"%f", cell.cardDetails.frame.origin.x);
                [UIView animateWithDuration: 0.5 animations:^{
                    cell.cardDetails.frame = CGRectOffset(cell.cardDetails.frame, -322.0, 0.0);
                    //        CGRectOffset(cell.cardView.frame, -320.0, 0.0);
                    cell.actionCardReminder.frame = CGRectOffset(cell.actionCardReminder.frame, -322.0, 0.0);
                }];
                NSLog(@"%f", cell.cardDetails.frame.origin.x);

    return cell;
    }

The view in cell moving as expected but not to the negative side. Its still showing the cardDetails view not the actionCardReminder view.

  • Loading Apple Pay Shipping Address No Street
  • Facebook posting error in ios
  • How to get ts frame from DJI phantom camera delegate for RTMP streaming to server
  • UIView drag (image and text)
  • Error using Swift - Instance member cannot be used on type 'ViewController'
  • UIButton not respect Aspect Fill contentMode after resizing animation
  • Note: The NSLog show the view frame as change x position but the view is not moving to -322.0 position.

    2 Solutions Collect From Internet About “Frame is not changing in cellForRowAtIndexPath”

    Because of the iOS layout render process, your custom UITableViewCell’s layoutSubviews may called more than once. In your case you can change the items frames in the GoalDetailsTableViewCell class’s layoutSubviews method.

    @implementation GoalDetailsTableViewCell
    
    -(void)layoutSubviews
    {
        [super layoutSubviews];
        [UIView animateWithDuration: 0.5 animations:^{
                        cell.cardDetails.frame = CGRectOffset(cell.cardDetails.frame, -322.0, 0.0);
                        //        CGRectOffset(cell.cardView.frame, -320.0, 0.0);
                        cell.actionCardReminder.frame = CGRectOffset(cell.actionCardReminder.frame, -322.0, 0.0);
                    }];
         NSLog(@"%f", cell.cardDetails.frame.origin.x);
    }
    @end
    

    Do not change the Frame in cellForRowAtIndexPath try Changing it in willDisplayingCell Method