1

I have two views in my application. One (by default) is Landscape. When the user clicks a certain menu, i need a Portrait view to appear.

I have all the code in place and i'm trying to use this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

But the app still displays the next view in Landscape. I can't figure this out. Any help will be great.

nworksdev
  • 235
  • 3
  • 11

2 Answers2

1
You can not do it using navigation controller but if you are presenting your view then it  is possible to do that and make sure when you are presenting your view animation should be NO.
It works for me very well.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
amit soni
  • 2,183
  • 1
  • 14
  • 17
0

You can use following code in your viewWillAppear method to make your view portrait.

 [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];
Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
  • It gives me the error : Cast of 'NSInteger' (aka 'int') to 'id' is disallowed with ARC. – nworksdev Oct 16 '12 at 04:49
  • Was able to build but unfortunately still no dice. Do i need a specific shouldAutorotateToInterfaceOrientation method? – nworksdev Oct 16 '12 at 04:55
  • No you dont need, please you comment whole `shouldAutorotateToInterfaceOrientation` method – Rahul Patel Oct 16 '12 at 04:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18085/discussion-between-nworksdev-and-rahul-patel) – nworksdev Oct 16 '12 at 04:58
  • if you are using ARC than you can disable it for this only single file and can run project successfuly. below is the link of disable ARC [link here](http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project) – Rahul Patel Oct 16 '12 at 04:59
  • @nworksdev If you use this, there's a very good chance of having your app rejected. – Jason Coco Oct 16 '12 at 05:13
  • @json coco: its still accepted code buudy. but `[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationAnyOrientation] `is depricated – Rahul Patel Oct 16 '12 at 05:16
  • @RahulPatel absolutely not. You're just avoiding making the call to `-setOrientation:` directly and are using the dynamic nature of objective-c to suppress the compiler error. That fact that its possible to dynamically dispatch calls doesn't make it okay and doesn't mean it won't be rejected (especially if he's targeting a modern version of iOS). – Jason Coco Oct 16 '12 at 15:40