Vladimir Stazhilov
Vladimir Stazhilov

Reputation: 1954

How to start the app with the UIViewController specified? not with the first

I've got view-based application, I don't want to start with the first standart view, how should I start with another view?!

Upvotes: 2

Views: 1637

Answers (4)

EmptyStack
EmptyStack

Reputation: 51374

You can change the MainWindow.xib file to add your view controller as the subview of the main window. Or, you can do it by code like this, in applicationdidFinishLaunchingWithOptions: method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    YourViewController *vc = [[YourViewController alloc] init];

     // You can add it as subView
    [self.window addSubview:vc]; 

    // Or, add it as rootViewController (available from iOS 4.0)
    self.window.rootViewController = vc;

    [vc release];
    [self.window makeKeyAndVisible];
    return YES;
}

Upvotes: 1

Toncean Cosmin
Toncean Cosmin

Reputation: 535

in application:didFinishLaunchingWithOption: just declare you new viewController and addIt

SomeViewController *svc = [[SomeViewController alloc] initWithFrame: ... ];
[self.window addSubview:avc.view];
[self.window makeKeyAndVisible];

Upvotes: 0

stack2012
stack2012

Reputation: 2186

you have to change it in the appdelegate like this...

 viewController=[[sampleFirst alloc]init];

self.window.backgroundColor = [UIColor blackColor];
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];

B4 tat u need to declare the sampleFirst viewcontroller class as a property in the appdelegate header file like this..(after declaring the viewcontroller object for sampleFirst viewcontroller class)

@property (nonatomic, retain) IBOutlet sampleFirst *viewController;

Upvotes: -1

rich
rich

Reputation: 2136

You need to assign the view controller you would like to load to the root view controller Place this in your app delegate with viewcontroller being the name of the view controller you would like to load

window.rootViewController = viewController  

Upvotes: 1

Related Questions