问题描述:

I'm working on a iPad with iOS7.

I have custom UITableViewController subclass that is working very well (i.e. it's displaying all the data as expected), except that it doesn't properly set the width when the device starts in landscape orientation.

If the app is started in portrait mode, the width of the table view is correct - it takes up the entire width of the screen. When I rotate to landscape view, it resizes the table view content to take up all available space. This is fine.

However, if I start the app in landscape view, the width of the table view is only about 3/4 of the available space. This incorrect width persists if I then rotate to portrait mode; the content is resized, but it still only takes up 3/4 of the available width/

I'm not using custom UITableViewCells, just UITableViewCellStyleSubtitle.

I've tried adding an autoresizingMask to both the cells and the UITableView. However, I'm not convinced I'm doing it in the right place. I've been setting the autoresizingMask in the init method of my TableViewController subclass:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth.

What do I need to do to get my table view to automatically fit the available width when starting in landscape mode?

网友答案:

If you do not create a UIView from a NIB, then you should either be passing physical dimensions to its initWithFrame, or set it using the frame property.

[[aSubView alloc] initWithFrame:someFrame];

As you pointed out, it is not the autoresizingMask that is incorrect, since the view does already resize, only improperly ; it's the view frame that is incorrect.

As an example, you may want to pass the bounds of the enclosing view, which will anchor your subview at (0,0) filling the superview in all directions.

[[aSubView alloc] initWithFrame:self.view.bounds];
相关阅读:
Top