Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-15-2010, 10:36 AM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 20
qahweh is on a distinguished road
Default Autoresizing UIViewController's view when pushing to UINavigationController's stack

I have a navigation-based application which uses a navigation bar and a navigation stack to which custom UIViewControllers are pushed. The problem is that when a new UIViewController is allocated, initialized and finally pushed to the stack, the height of this controller's view does not fit to the screen. I mean, for example an y-position self.view.frame.size.height - 10 is drawn offscreen. It seems that the size of the my controller's view does not take account the navigation bar.

I tried using autoresizing mask in viewDidLoad and loadView but nothing seems to work. Any help would be appreciated.

This is the pushing action called when a user hits a button:
Code:
NaviAppDelegate *appDelegate = (NaviAppDelegate *)[[UIApplication sharedApplication] delegate];

UINavigationController *navigationController = appDelegate.navigationController;

MyGameViewController *aViewController = [[MyGameViewController alloc] init];

[navigationController pushViewController:aViewController animated:YES];
and in MyGameViewController.m i have:

Code:
- (void)loadView {
    [super loadView];
    self.view.autoresizesSubviews = YES;
    self.view.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
}

- (void)viewDidLoad {
   [super viewDidLoad];

   int f = 10;

   self.graphView = [[UIView alloc] initWithFrame:CGRectMake(f,f,self.view.frame.size.width-2*f, self.view.frame.size.height-2*f)];
   
   graphView.backgroundColor = [UIColor blueColor];
	
   [self.view addSubview:graphView];
}
The viewDidLoad method should create a blue rectangle drawn to the screen with margins of 10px in each direction. But the margins appear only on the upper, left and right directions... bottom does not have any margin.
qahweh is offline   Reply With Quote
Old 05-16-2010, 03:28 AM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 20
qahweh is on a distinguished road
Default

Okay, so apparently the controller's view was autoresized correctly but graphview wasn't. I fixed this by adding

Code:
graphView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
to viewDidLoad.
qahweh is offline   Reply With Quote
Old 08-04-2010, 08:39 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 2
palmerc is on a distinguished road
Default loadView not viewDidLoad

I really try to avoid loading views in the view controllers -(void)viewDidLoad method. You can accomplish the same thing in the more appropriate -(void)loadView method.

Code:
- (void)loadView {
	CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
	UIView *aView = [[UIView alloc] initWithFrame:applicationFrame];
	
	webView = [[UIWebView alloc] initWithFrame:aView.bounds];
	webView.backgroundColor = [UIColor yellowColor];
	webView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
	webView.dataDetectorTypes = UIDataDetectorTypeAll;
	
	[aView addSubview:webView];	
	
	self.view = aView;
	[aView release];
}
palmerc is offline   Reply With Quote
Reply

Bookmarks

Tags
autoresizingmask, uinavigationcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 312
11 members and 301 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, jbro, n00b, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:47 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0