Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 29, 2011, 06:45 AM   #1
kamy
macrumors newbie
 
Join Date: Jul 2011
iPad - Orientation issue - addSubView,RemoveFromSuperView

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.
kamy is offline   0 Reply With Quote
Old Jul 29, 2011, 08:34 PM   #2
Sykte
macrumors regular
 
Join Date: Aug 2010
Quote:
Originally Posted by kamy View Post
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.
__________________
Looking for apple/tech news on your IPhone or IPod touch, Try out PowerFeed. 100% free.
Sykte is offline   0 Reply With Quote
Old Jul 30, 2011, 11:57 PM   #3
kamy
Thread Starter
macrumors newbie
 
Join Date: Jul 2011
Quote:
Originally Posted by Sykte View Post
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
kamy is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iOS 7 Orientation Issue - Hardware or Software Issue? GandalfBR iPad Tips, Help and Troubleshooting 2 Dec 7, 2013 07:59 PM
iOS 7 Orientation Issue - Hardware or Software Issue? GandalfBR iOS 7 6 Nov 16, 2013 04:56 PM
cocoa n cocos2d orientation issue zunaira iOS 5 and earlier 1 Mar 13, 2013 09:41 PM
All iPads: In which orientation do you use your iPad the most? kylera iPad 37 Jan 28, 2013 10:00 PM
iPad Landscape Orientation Issue lukeman3000 iPad 9 Sep 19, 2012 06:18 PM

Forum Jump

All times are GMT -5. The time now is 05:27 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC