开发者

iPhone :: Objective-C - AddSubview in my initial UIViewController ViewDidAppear

开发者 https://www.devze.com 2023-04-05 10:12 出处:网络
Hihi all, This could very well be a silly question. I would like to navigate to my \"Login View\" upon the launching of my application. My current tries:

Hihi all,

This could very well be a silly question. I would like to navigate to my "Login View" upon the launching of my application. My current tries:

  1. In my first UIViewController's viewDidAppear method, perform a [self presentModalViewController:LoginView animated:YES], this works, but the screen shows my main UIView first, then slide my LoginView from bottom to top. I can't find a way to perform it without the animation.

  2. In my first UIViewController's viewDidAppear method, perform a [self.view addSubview:LoginView.view], it ends up with exc_bad_access error.

Basically, my requirement is to perform certain checks开发者_Python百科 upon starting of the application, if a login is required, the application shall display the LoginView, otherwise, it should stay as my main UIView.

Please advice what is the best way of achieving this, instead of the above two silly methods. Thanks in advance!

:)


How about trying it in **- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {**

example :

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

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    LoginViewController *aLoginViewController = [[LoginViewController alloc] init];
    [self.navigationController presentModalViewController:aLoginViewController animated:NO];
    [aLoginViewController release];

    return YES;
}


your 1st step is a good way.. but to stop animation, its very simple. Set animated to NO.

[self presentModalViewController:aLoginViewController animated:NO];

once ur done with ur validation, just dismiss this aLoginViewController.


Instead of -viewDidAppear, it sounds like you want to use -viewWillAppear:, which will allow you to present your login controller before the initial view is displayed.

-presentModalViewController:animated is the right method to display your login controller's view.

0

精彩评论

暂无评论...
验证码 换一张
取 消