Add a subview via 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 the wrong screen height. I want my myTableView to have size.height-49.0

+3
source share
2 answers

Launch tableView using the CGRectZeroin method viewDidLoad, and then in the method viewWillAppear:set self.myTableView.framehow the presentation geometry is already set in this method and self.view.boundswill be correct. So, in the general case: init views in viewDidLoad, but set their geometry to viewWillAppear:.

+2
source

How about this?

CGRect r = initWithFrame:self.view.bounds;
r.size.height -= 49.0;
self.myTableView = [[UITableView alloc] initWithFrame:r];

Hope this helps ...

0
source

All Articles