How to start the app with the UIViewController spe

2019-05-20 22:35发布

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

4条回答
放我归山
2楼-- · 2019-05-20 23:02

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

SomeViewController *svc = [[SomeViewController alloc] initWithFrame: ... ];
[self.window addSubview:avc.view];
[self.window makeKeyAndVisible];
查看更多
甜甜的少女心
3楼-- · 2019-05-20 23:08

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;
}
查看更多
淡お忘
4楼-- · 2019-05-20 23:18

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;
查看更多
Deceive 欺骗
5楼-- · 2019-05-20 23:20

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  
查看更多
登录 后发表回答