Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewController last Row cut off

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

like image 884
user959974 Avatar asked Oct 06 '11 18:10

user959974


3 Answers

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;
like image 125
chown Avatar answered Sep 28 '22 09:09

chown


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);
like image 34
vishnu Avatar answered Sep 28 '22 08:09

vishnu


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;
like image 42
Robin Summerhill Avatar answered Sep 28 '22 10:09

Robin Summerhill