Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kamy

macrumors member
Original poster
Jul 27, 2011
44
0
Hi experts,

In my universal app, this is the order in which i load views, when my app loads

AppDelegate to FirstVIEW - didFinishLaunchingWithOptions event
Code:
[window addSubview:VIEW1];
 [window makeKeyAndVisible];


FirstVIEW to LOGINVIEW
Once i finish doing pre-login stuff, i navigate to Login view

Code:
LoginViewController_iPad *lsvc = [[LoginViewController_iPad alloc] initWithNibName:@"LoginViewController_iPad" bundle:Nil];
SDEAppAppDelegate_iPad *myAppDelegate = (SDEAppAppDelegate_iPad *) [[UIApplication sharedApplication] delegate];	

[lsvc.view setFrame:[[UIScreen mainScreen]applicationFrame]];
	
[myAppDelegate.window addSubview:lsvc.view];

LOGINview to MAINViewWithTabControllers
Once i finish doing authentication after login, i navigate to main view, where i have 3 tabs, 2 tabs have a splitview controllers in em. (iPad)

Code:
Code:
//Remove the login view and the pre-login view
while([[myAppDelegate.window subviews] count]) 
{
	[[myAppDelegate.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}

//Adding the tab bar main view
[myAppDelegate.window addSubview:myAppDelegate.myTabBarController.view];
[myAppDelegate.window makeKeyAndVisible];


My questions are,

a) every time i add a view, do i have to use 'myAppDelegate.window' and then invoke the addsubview() method or can we use '[self addSubview]'?

b) while removing the main view, do i have to remove the others views, before adding the main view?


Code:
Code:
//Remove the login view and the pre-login view
while([[myAppDelegate.window subviews] count]) 
{
	[[myAppDelegate.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
This kind of navigation is causing all sorts of issues on orientation change on the iPAD, even though all the view controllers return 'YES' in 'shouldAutorotateToInterfaceOrientation' event.
 

Sykte

macrumors regular
Aug 26, 2010
223
0
Hi experts,

In my universal app, this is the order in which i load views, when my app loads

AppDelegate to FirstVIEW - didFinishLaunchingWithOptions event
Code:
[window addSubview:VIEW1];
 [window makeKeyAndVisible];


FirstVIEW to LOGINVIEW
Once i finish doing pre-login stuff, i navigate to Login view

Code:
LoginViewController_iPad *lsvc = [[LoginViewController_iPad alloc] initWithNibName:@"LoginViewController_iPad" bundle:Nil];
SDEAppAppDelegate_iPad *myAppDelegate = (SDEAppAppDelegate_iPad *) [[UIApplication sharedApplication] delegate];	

[lsvc.view setFrame:[[UIScreen mainScreen]applicationFrame]];
	
[myAppDelegate.window addSubview:lsvc.view];

LOGINview to MAINViewWithTabControllers
Once i finish doing authentication after login, i navigate to main view, where i have 3 tabs, 2 tabs have a splitview controllers in em. (iPad)

Code:
Code:
//Remove the login view and the pre-login view
while([[myAppDelegate.window subviews] count]) 
{
	[[myAppDelegate.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}

//Adding the tab bar main view
[myAppDelegate.window addSubview:myAppDelegate.myTabBarController.view];
[myAppDelegate.window makeKeyAndVisible];


My questions are,

a) every time i add a view, do i have to use 'myAppDelegate.window' and then invoke the addsubview() method or can we use '[self addSubview]'?

b) while removing the main view, do i have to remove the others views, before adding the main view?


Code:
Code:
//Remove the login view and the pre-login view
while([[myAppDelegate.window subviews] count]) 
{
	[[myAppDelegate.window subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
This kind of navigation is causing all sorts of issues on orientation change on the iPAD, even though all the view controllers return 'YES' in 'shouldAutorotateToInterfaceOrientation' event.


Take a look at the UIViewController documentation along with UINavigationController documentation.
 

kamy

macrumors member
Original poster
Jul 27, 2011
44
0
Take a look at the UIViewController documentation along with UINavigationController documentation.

Hey Skyte,

Thanx for the tip...

I was reading this
http://developer.apple.com/library/i...88/_index.html


You may find a situation where shouldAutorotateToInterfaceOrientation is called once at startup for a given view controller but is never called again when the device is rotated. Because view controllers are tightly bound to the views they manage, they are also part of the responder chain used to handle events. View controllers are themselves descendants of the UIResponder class and are inserted into the responder chain between the managed view and its superview. So it is common practice to have one primary view controller in your application as part of the responder chain. You would typically add one primary view controller such as a UINavigationController, UITabBarController or a generic UIViewController to your UIWindow. For example, this is done by calling:

[window addSubviewrimaryViewController.view];

If you add an additional view controller's UIView property to UIWindow (at the same level as your primary view controller) via the following:

[window addSubview:anotherController.view];


Holy crow...all this time, i really have really been abusing UIViewController...i have been adding multiple views to 'myWindow' and thus additional view controllers will not receive rotation events and will never rotate. Only the first view controller added to UIWindow will rotate.

So i was wondering for Tab based applications, on the iPad
some of the questions that come to mind are
a) [window addSubview]
Do we need to do this only once during the AppDelegate's didFinishLaunchingWithOptions event

And ideally, this view has to be a UINavigationViewController or a
UITabViewController...right?

b) If this is the case, i wonder how do i achieve this?
iPAD app to navigate from
App Delegate --> Pre Login View (no tab) --> Login View (no tab)--> Home View (3 tabs)

So when i start the app, i could add the pre-login view and login view to the UITabViewController and show it and hide tabs.
Once pre-login process is complete, i could show login view without the tabs....once user logs-in, i could show the main view (3 tabs - 1 tab has a normal view, the other 2 tabs have a splitviewcontroller)....

when user logs out, i can again show the login-view and hide the tabs...

So essentially the UITabViewController object manages all my views and thus i should not face any rotation issues right?


Please let me know, if i could do something different here?
Thanx in advance
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.