Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add subview through initWithFrame. UINavigationBar size

I have a View with UINavigationBar: AppDelegate:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

_homeScreen = [[PrepareScreen alloc] init];
self.mainViewController = [[MyViewController alloc] initWithScreenDef:[self.homeScreen projectHomeScreen] AndBounds:self.window.bounds];

self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.mainViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;

And then i have a class

MyViewController : UIView <UITableViewDataSource,UITableViewDelegate>

And in my .h file i have:

- (void)viewDidLoad
{
[super viewDidLoad];

self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.myTableView];
}

After that i have a wrong height of a screen. I want that my myTableView have a size.height-49.0

like image 924
Jakub Avatar asked May 18 '26 06:05

Jakub


1 Answers

Init the tableView with CGRectZero in viewDidLoad method and then in the method viewWillAppear: set the self.myTableView.frame as in this method the view's geometry is already set and self.view.bounds will be correct. So in general: init views in viewDidLoad, but set their geometry in viewWillAppear:.

like image 70
graver Avatar answered May 19 '26 18:05

graver