16

I am experiencing a problem where in my UITableViewController, the last row is always cutoff by half.

If I have 20 rows, the 20th will be cut off; if I have 30, the 30th will be cut off.

I tried to resize the contentSize, and the frame of the UITableViewController, but it doesn't work.

Is there a way to resize the UITableViewController to the correct size?

Thanks in advance.

Some Code:

Initialize it in another class:

 settingsTable = [[SettingTableViewController alloc] init];
    settingsTable.view.frame = CGRectMake(0, 0, 320, 480);
    [self.view addSubview:settingsTable.view];

in the UITableViewController:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [settingsData count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[settingsData objectForKey:[NSString stringWithFormat:@"%d", section]] objectAtIndex:0];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[settingsData objectForKey:[NSString stringWithFormat:@"%d", section]] objectAtIndex:1] intValue];
}

I didn't resize the frame anywhere in the UITableViewController

3
  • You are probably setting the frame of the UITableView wrong in the firstplace. Providing some code would help:)
    – LuckyLuke
    Oct 6, 2011 at 18:44
  • You said that you tried to resize the ViewController but still, could it be, that you used Interface Builder to place the view and, if so, did leave place eventual NavigationBars or TabBars? Oct 6, 2011 at 18:47
  • @Phlibbo It's not loaded from .xib file though..
    – user959974
    Oct 6, 2011 at 18:51

7 Answers 7

16

In the interface builder, select the UITableView and then under the View options remove the bottom autoresizing bar. You can leave all the others the way they are if they are different from the screenshots below. The important one is the bottom vertical bar.

Change this:

Before

To this:

After

Or, to do it programmatically:

settingsTable.autoresizingMask &= ~UIViewAutoresizingFlexibleBottomMargin;

Edit (from comments):

Is your status bar set to showing or hidden? If it is showing then change the frame line to:

settingsTable.view.frame = CGRectMake(0, 0, 320, 460);

Or, try either one of these and see if they help:

settingsTable.view.frame = self.view.bounds;
// or
settingsTable.view.frame = self.view.frame;
2
  • 1
    I changed the settingsTable.autoresizingMask &= ~UIViewAutoresizingFlexibleBottomMargin;, then the last row is gone entirely 0-0... When i change it to "UIViewAutoresizingFlexibleHeight", the last row is cut by about 1/5 ..
    – user959974
    Oct 6, 2011 at 19:08
  • Or, you could just do this: settingsTable.view.frame = self.view.bounds; or settingsTable.view.frame = self.view.frame;
    – chown
    Oct 6, 2011 at 19:14
12

when using UITableViewController inside container-controllers & translucent UI-bars is set), so I think it is "app's side" to properly handle its contentInset.

You can try

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
4

The problem is this line:

settingsTable.view.frame = CGRectMake(0, 0, 320, 480);

You are not accounting for the height of the status bar (20px in portrait orientation). The total available height is actually 460px not 480px. That is why you are losing 20px at the bottom. You should calculate frames for laying out subviews based on the parent view bounds rather than hardcoding them:

settingsTable.view.frame = self.view.bounds;
0
1

You can use following code

//Checking for device Orientation
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight))
    {
        NSLog(@"Landscape");
        //setting the height of the tableview  (height of tableview - height of Navbar)
        self.messageTableView.contentInset = UIEdgeInsetsMake(0, 0, self.view.frame.size.height-64, 0);
    }
    else
    {
        NSLog(@"Portrait");
        self.messageTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }
}
0

I had a similiar problem in iOS 8

Simply adjusting the section footer height in my tableView solved the issue.

enter image description here

0

When working with Auto-Layout ensure that your tableView's bottom constraint is set to 0 relative to it's container.

for setting it through code (PureLayout)

[tableView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:containerView withOffset:0];
-1

Could be your constraints, I just had this problem till I found my tableview was constrained to superview height & width but was accidentally centred in the safe area x & y which was cutting off the bottom..

1
  • I left this answer as I looked at this post to try to fix the same problem in 2018 and this was the reason I was experiencing the issue. I think it is valid to leave it here as it may help someone searching the problem at this time like I did and I certainly don't appreciate the down vote! Dec 20, 2018 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.