0

I am working on a universal application.I am using

self.window.rootViewController = self.SecondViewController

to load viewcontroller class in the AppDelegate method. This line of code is working fine for ios versions 4 and later but when i run it on my ios 3.1.3 it crashes.

So I replaced that code with [self.window addSubview:[SecondViewController view]] and it works fine but initially the view moves up(As in the screen shot) when we load the app for the first time.

So kindly help me overcome this issue thank you enter image description here

IronManGill
  • 7,222
  • 2
  • 31
  • 52
sujay
  • 1,845
  • 9
  • 34
  • 55
  • Why... 1. dod you use the Xcode tag? (Now go read its tag wiki!) 2. would you want to support iOS 3? –  Sep 18 '12 at 05:05
  • first time check witch device version you r using as per device version set your code – Ayaz Sep 18 '12 at 05:16
  • @Ayaz: i am using ios 3.1.3.In which the view is moving up and it makes my app look weird. – sujay Sep 18 '12 at 05:31

2 Answers2

3

The rootViewController property was introduced with iOS 4.0, that is the reason for the crash in iOS 3.1.3.

If you use [self.window addSubview:[SecondViewController view]] then it can happen that the view controllers view is not adjusted for the status bar. See Offset on UIWindow addSubview for a good explanation.

The solution is to assign the view's frame, in your case

self.SecondViewController.view.frame = [UIScreen mainScreen].applicationFrame;

before adding it as subview.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
2
SecondViewController.view.frame = CGRectMake(0, 20, 320, 460);
[self.window addSubview:[SecondViewController view]]
Ganee....
  • 302
  • 2
  • 13