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 07-03-2010, 03:59 PM   #1 (permalink)
Luc
Registered Member
 
Join Date: Jul 2010
Posts: 4
Luc is on a distinguished road
Default Cannot switch back from my landscape view to a portrait view

Hello,

I am working on an app (my first one), which is basically a TabBar app.
To be more precise there are:
- a login view controller
- a tab bar controller (when login is done)
- a landscape view controller that is used when the first itel of the TabBar is switch from Protrait to Landscape.

So, when I am in the first tab, I need to be able to move to landscape view to display some other data. In my tab bar controller, I have implemented those methods:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0)
return YES;

return NO;
}


- (void)willRotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation durationNSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrient ation duration:duration];

// Get AppDelegate
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Remove TabBarView and add graph Landscape View
[self.view removeFromSuperview];
[delegate setSubViewLandscapeViewController];
}
}

In the delegate, I have implemented the setSubViewLandscapeViewController and the setSubViewTabBarController to switch between the different View controller:

- (void)setSubViewTabBarViewController {
[window addSubview:[tabBarController view]];
}

- (void)setSubViewGraphLandscapeViewController {
[window addSubview:[landscapeViewController view]];
}

I want the landscapeViewController to display only in landscape mode, I have then (in my landscapeViewController):

- (void)viewWillAppearBOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRigh t];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)willRotateToInterfaceOrientationUIInterfac eOrientation)toInterfaceOrientation durationNSTimeInterval)duration {

NSLog(@"willRotateToInterfaceOrientation");
}

A part of this works fine, I mean the switch from portrait to landscape is ok (when I am in the first tab), the tabbarcontroller is remove from the SuperView and the landscape view is added as a subview instead.

The thing is... I do not know how to switch back to portrait mode (and then load the previous controller, the tabBar one using the setSubViewTabBarViewController of my delegate). It seems none of the willRotateToOrientation, willRotateFromOrientation, .. are triggered when I actually move the device from the landscape view...

In short, when I am in the landscape view I do not know what to do to move back to the tabbar view... I am kind of stuck in the landscape view once I am in this one.

Thanks a lot for your help,

Luc
Luc is offline   Reply With Quote
Old 07-14-2010, 03:15 AM   #2 (permalink)
Tutorial Author
 
Join Date: Feb 2009
Posts: 223
mr tickle is on a distinguished road
Default

hi luc

i checked some of the code out, im on holiday until saturday at the moment, on a beach :-)

some things that i can tell you that make the whole process of managing and controlling any app in iphone/ipad is this

1. to access views, i notice that you use bracket instead of dot access, you dont need to, a view can be accessed like this

[self.view addSubview:mycontroller.view];

sometimes that makes things easier to read, i only use bracket access on things like arrays, method calls ( [ myclass mymethod] )

2. generally keep away from the appdelegate when you create an app, obviously this is not a necesity that you need to follow, but i find that it helps a lot, the delegate can be used to initialize the project or app you create, for example, because the objective element of xcode sdk is so flexible, you can have a structure like this

myappdelegate
>> maincontroller > view
>>>> myportraitcontroller > view
>>>> mylandscapecontroller > view

this means that your main controller has dominance over all classes directly under it, so in the willrotatetointerfaceorientation, you can tell the different controllers to do things, or alternatively, do things directly in the maincontroller

im going to take a closer look at the problem and get back to you.

Paul
mr tickle is offline   Reply With Quote
Reply

Bookmarks

Tags
landscape, tab bar controller

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: 327
6 members and 321 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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