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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 11-23-2009, 03:56 PM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 211
Default Rotating a view within a navigation controller inside of a tab bar controller

I have an app with 4 tab bar entries, all but one holding a navigation controller, which then contains the stack of individual view controllers. How can I autorotate one of these view controllers?

Whenever I override the shouldRotateTo... method in one of these view controllers, the view controller will still never respond to autorotation events.

How can I make this work, preferably without having to tear apart my app in the process? Thanks in advance.
__________________
www.thomashuntington.com

Political GPS - Track your Congress and Find Yourself.
Apple New and Noteworthy

Nightstand Central - Music Alarm Clock with Weather, Photos, and Sleep Timer
Apple Staff Favorite - Top 10 iPhone Paid Productivity, Top 5 Free iPad Overall
csnplt is offline   Reply With Quote
Old 11-25-2009, 12:15 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: Pune, India
Posts: 314
Send a message via Skype™ to Akshay Shah
Cool

Quote:
Originally Posted by csnplt View Post
I have an app with 4 tab bar entries, all but one holding a navigation controller, which then contains the stack of individual view controllers. How can I autorotate one of these view controllers?

Whenever I override the shouldRotateTo... method in one of these view controllers, the view controller will still never respond to autorotation events.

How can I make this work, preferably without having to tear apart my app in the process? Thanks in advance.
To do this,
Subclass UITabBarController and override the shouldRotateTo... method.
This would do your trick...

Regards,
Akshay Shah.
__________________
If you think I did help you, you can always thank me by buying
iHoldMore - A very nice and addictive game...

Need a mobile app. Contact Us.
Ruby Solutions Pvt. Ltd.
You can mail me at akshay@ruby-solutions.com
Akshay Shah is offline   Reply With Quote
Old 11-25-2009, 11:00 PM   #3 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 211
Default

Quote:
Originally Posted by Akshay Shah View Post
To do this,
Subclass UITabBarController and override the shouldRotateTo... method.
This would do your trick...

Regards,
Akshay Shah.
That helped me. Thanks.

Now, however, all of my views within the tab bar autorotate, when I only want one of them to do so. Can I fix this?
__________________
www.thomashuntington.com

Political GPS - Track your Congress and Find Yourself.
Apple New and Noteworthy

Nightstand Central - Music Alarm Clock with Weather, Photos, and Sleep Timer
Apple Staff Favorite - Top 10 iPhone Paid Productivity, Top 5 Free iPad Overall
csnplt is offline   Reply With Quote
Old 11-25-2009, 11:18 PM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 211
Default

Quote:
Originally Posted by csnplt View Post
That helped me. Thanks.

Now, however, all of my views within the tab bar autorotate, when I only want one of them to do so. Can I fix this?
Just figured it out. In the subclass of the tab bar controller, in shouldAutorotate..., I check the class of the currently displayed VC. If it is a navigationController, I check its visible view controller's class, and if that is equal to the view controller that I want to autorotate, I allow autorotation. Otherwise, I don't.

Here's the code:
Code:
if([self.selectedViewController isKindOfClass:[UINavigationController class]])
	if([[self.selectedViewController visibleViewController] isKindOfClass:[WebsiteViewController class]])
		return (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
__________________
www.thomashuntington.com

Political GPS - Track your Congress and Find Yourself.
Apple New and Noteworthy

Nightstand Central - Music Alarm Clock with Weather, Photos, and Sleep Timer
Apple Staff Favorite - Top 10 iPhone Paid Productivity, Top 5 Free iPad Overall

Last edited by csnplt; 11-25-2009 at 11:19 PM. Reason: CODE Brackets
csnplt is offline   Reply With Quote
Old 03-17-2010, 08:15 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default works with warning

Thanks for this solution. However, I get the warning: 'UIViewController' may not respond to '-visibleViewController'

It works nonetheless, but is there a way I can do it without the warning?
intomo is offline   Reply With Quote
Old 03-28-2010, 11:02 PM   #6 (permalink)
iPhone Developer
 
Join Date: Mar 2010
Posts: 1
Default

Quote:
Originally Posted by intomo View Post
Thanks for this solution. However, I get the warning: 'UIViewController' may not respond to '-visibleViewController'

It works nonetheless, but is there a way I can do it without the warning?
You have to cast to UINavigationController.
---
Uruguay Radios
jedilp is offline   Reply With Quote
Old 03-29-2010, 11:57 AM   #7 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
	if([(UINavigationController *)self.selectedViewController isKindOfClass:[UINavigationController class]])
		if([[(UINavigationController *)self.selectedViewController visibleViewController] isKindOfClass:[MediaDetailViewController class]])
			return (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I still get one error saying that MediaDetailViewController is a forward class and may not respond to @interface...

Am I still doing something wrong?
Thanks for the thread.
intomo is offline   Reply With Quote
Old 04-18-2010, 01:40 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 62
Default

Ah, this was addressed in this link Objective-C @class vs. #import - Stack Overflow
I was missing an #import
intomo is offline   Reply With Quote
Old 09-08-2010, 11:36 AM   #9 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 8
Default

Quote:
Originally Posted by intomo View Post
Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
	if([(UINavigationController *)self.selectedViewController isKindOfClass:[UINavigationController class]])
		if([[(UINavigationController *)self.selectedViewController visibleViewController] isKindOfClass:[MediaDetailViewController class]])
			return (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I still get one error saying that MediaDetailViewController is a forward class and may not respond to @interface...

Am I still doing something wrong?
Thanks for the thread.
Use self.selectedIndex works for me. I only allow rotating view at index 3 in my app.

Thanks,
tuyennguyencanada is offline   Reply With Quote
Reply

Bookmarks

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: 258
18 members and 240 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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