iphone - Objetive c - proper way to set subview frame so it will fill the screen -


i have viewcontroller inside of navigationcontroller, view controller has tableview.
in viewdidload set tablview

- (void)viewdidload {     [super viewdidload];      // init tableview     cgrect tableframe = self.view.bounds;      _tableview = [[uitableview alloc] initwithframe:tableframe style:uitableviewstyleplain];      _tableview.delegate = self;     _tableview.datasource = self;      [self.view addsubview:_tableview]; } 

the problem code table view frame not correct - height 460 , need 416.

[the iphone screen height 480, minus status bar (20) minus navigation bar (44) = 416]

so proper way set table view fill screen?
can think of 2 ways:

  1. set frame = (0, 0, 320, 416)

  2. use:

    [_tableview setautoresizingmask:(uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth)];

don't use magic numbers. use resizing flags correctly. yes, 2. approach correct.

1) use superviews bounds.
_tableview.frame = self.view.bounds;;

2) set autoresizing flags
[_tableview setautoresizingmask: uiviewautoresizingflexibleheight | uiviewautoresizingflexiblewidth];

(you did of :)


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -