Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:48:53+00:00 2026-06-14T08:48:53+00:00

I have created Custom UITableViewCell using XIB file and got it working in UITableView.

  • 0

I have created Custom UITableViewCell using XIB file and got it working in UITableView. I have designed custom cell and it’s subviews in portrait sizes but when I rotate device in landscap mode I want to resize cell and it’s subviews. I have written following code for this but not sure why only one cell in visible cells get resized and rest stays same! Could someone please help me with the standard practice to resize custom cell and their subviews? Thanks.

#pragma mark - UITableView delegate methods

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CustomTableViewCellIdentifier";
    CustomTableViewCell *cell = (CustomTableViewCell*)[tv dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        // Load custom cell from NIB
        self.customTableViewCell = [[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil] objectAtIndex:0];
        cell = _customTableViewCell;
    }
    // Use cell
    ...
}

#pragma mark - Layout views

- (void)layoutForOrientation:(UIInterfaceOrientation)orientation {
    if (UIInterfaceOrientationIsPortrait(orientation))
        [self layoutPortraitViews];
    else
        [self layoutLandscapViews];
}

- (void)layoutLandscapViews {
    self.customTableViewCell.frame = CGRectMake(0, 0, 1024, 40);
    self.customTableViewCell.contentSize = CGSizeMake(1024, 40);
    self.customTableViewCell.cellBackgroundImageView.frame = CGRectMake(0, 0, 1024, 40);
    self.customTableViewCell.assetNameLabel.frame = CGRectMake(15, 0, 245, 20);
    self.customTableViewCell.assetTypeLabel.frame = CGRectMake(15, 20, 245, 20);
    self.customTableViewCell.assetImageView.frame = CGRectMake(265, 20, 120, 20);
    self.customTableViewCell.assetValueLabel.frame = CGRectMake(265, 20, 120, 20);

    [self.tableView reloadData];
}

- (void)layoutPortraitViews {
    self.customTableViewCell.frame = CGRectMake(0, 0, 768, 40);
    self.customTableViewCell.contentSize = CGSizeMake(768, 40);
    self.customTableViewCell.cellBackgroundImageView.frame = CGRectMake(0, 0, 768, 40);
    self.customTableViewCell.assetNameLabel.frame = CGRectMake(15, 0, 180, 20);
    self.customTableViewCell.assetTypeLabel.frame = CGRectMake(15, 20, 180, 20);
    self.customTableViewCell.assetImageView.frame = CGRectMake(200, 20, 90, 20);
    self.customTableViewCell.assetValueLabel.frame = CGRectMake(200, 20, 90, 20);

    [self.tableView reloadData];
}

[SOLUTION]

After little struggle got this working. Changing the size of cell and it’s subviews not going to work as I have to handle orientation changes, keep reusing cell for performance, and visible cells changes when you rotate the device so couldn’t figure out the solution using my first approach. Here is my another solution.

Here challenge is to handle orientations and custom cells together without compromising performance.

I have created two cell views in NIB, one for portrait and another for landscap.

Used two variables;

BOOL refreshing;
UIInterfaceOrientation currentOrientation;

From view will appear;

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
    [self layoutForOrientation:[UIApplication sharedApplication].statusBarOrientation];
}

From rotation delegates;

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    refreshing = YES;
    currentOrientation = toInterfaceOrientation;
    [UIView animateWithDuration:duration animations:^{
        [self.tableView reloadData];
        [self layoutForOrientation:toInterfaceOrientation];
    }];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    refreshing = NO;
}

From tableview delegate;

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CustomTableViewCellIdentifier";
    CustomTableViewCell *cell = (CustomTableViewCell*)[tv dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil || refreshing)
     {
        if (UIInterfaceOrientationIsPortrait(currentOrientation))
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil] objectAtIndex:0];
         else 
            cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil] objectAtIndex:1];
    }

    //Use cell
}

…so this solution will reload cells only when orientation changed event happens. Happy coding 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:48:55+00:00Added an answer on June 14, 2026 at 8:48 am

    Resizing a custom NIB xib cell may or may not provide the desirec UI on rotation.To make the task easier..create two UITableViewCell nibs

     if (!cell) {
                if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
                    [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell-Landscape" owner:self options:nil];
                }else {
                    [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
         }
    }
    

    Further call [tableView reloadData]; on orientation change

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a UITableView with a custom UITableViewCell . My cell includes one
I've created a custom cell class using these instructions: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/ Everything worked great, except
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom view with a XIB file and are loading the
I'm using a custom UITableViewCell I've created to expand a cell when it's touched.
i have created a custom UITableViewCell , but when I dequeue the cell, sometimes
I've a custom table view cell that I created using XIB: I've also linked
I have created a custom subclass of UITableViewCell. There, I allow the user to
I have created custom cell in which there are n number of image views.
I have created a custom cell for loading into a table. The interface is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.