I have learned that the proper way to set a UITableView
that covers up the whole main view (full width and full height), in a Single View app is, in viewDidLoad
:
table = [[UITableView alloc] initWithFrame:self.view.bounds];
table.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
[self.view addSubview:table];
note that if a physical iPad 2 is held at Landscape mode, and if the self.view.bounds
above is printed inside viewDidLoad
, it will show: {{0, 0}, {768, 1004}}
. So I thought the idea is: don't worry the width and height not being correct, because the UIViewAutoresizingFlexibleWidth
and UIViewAutoresizingFlexibleHeight
will take care of setting the correct width and size automatically.
So I actually tried replacing the above first line by:
table = [[UITableView alloc] init];
or
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
or even
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1004, 768)];
or the ultimately "correct value":
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];
when the iPad 2 is held at Landscape position. But now the table won't fully expand to the whole main view. So what is the governing principle here? The width and height can be set incorrectly, but it must be incorrectly at {768, 1004}
? It can't be "incorrect" with other values? If no CGRect
was given, or some dummy values {200, 200}
was given, what should the code in viewDidLoad
do to make the table have the full main view's width and height whether it is Landscape or Portrait mode?