Can not push modal views after adding subview to window?

In my application, I have the following code, the first bit is triggered when my application starts, and it is a screen for entering the modal view. When my rootController is added to the window before.

The modal view allows the user to log in, view the conditions, and then, if they accept the loadMainApp function, is called.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    rootController.delegate = self;
    [window addSubview:rootController.view];

    LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
    self.loginViewController = _loginViewController;
    [_loginViewController release];


    UINavigationController *navi = [[[UINavigationController alloc]initWithRootViewController:loginViewController]autorelease];

    navi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [loginViewController release];
    [rootController presentModalViewController:navi animated:YES];

    [self.window makeKeyAndVisible];
    return YES;
}

This next bit is called when the user accepts the conditions:

-(void)loadMainApp:(UIView *)fromView{

    [fromView removeFromSuperview];
    [window addSubview:rootController.view];
    rootController.selectedIndex = 2;
    rootController.delegate = self;

}

From here, I want to be able to use the people picker, which is a modal view, and I'm trying to execute it with this code:

 ABPeoplePickerNavigationController *picker =
        [[ABPeoplePickerNavigationController alloc]init];
        picker.peoplePickerDelegate = self;

        [rootController presentModalViewController:picker animated:YES];
        [picker release];

But nothing happens when I try to present a modal view from my rootController, nothing is displayed.

, , applicationDidFinishLaunching:

LoginViewController *_loginViewController = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:[NSBundle mainBundle]];
        self.loginViewController = _loginViewController;
        [_loginViewController release];


        UINavigationController *navi = [[[UINavigationController alloc]initWithRootViewController:loginViewController]autorelease];

        navi.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        [loginViewController release];
        [rootController presentModalViewController:navi animated:YES];

        [self.window makeKeyAndVisible];
        return YES;

rootController

rootController.delegate = self;
        [window addSubview:rootController.view];

applicationDidFinishLaunching, , , .

- , - , ?

+3
2

, dismissModalViewControllerAnimated:? , , , UIKit.

+2

, , - :

  • rootViewController navigationController. navigationController .

  • rootViewController viewDidLoad loginViewController rootViewController LoginViewController .

  • , [delegate loginViewControllerFinished];.

  • rootViewController loginViewControllerFinished. [self rejectModalViewControllerAnimated: YES]; . ABPeoplePickerNavigationController .


AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Make sure rootViewController is initiated by this point.

    UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];

    [window addSubview:rootController.view];
    [self.window makeKeyAndVisible];
    return YES;
}

RootViewController:

- (void)viewDidLoad {
  [super viewDidLoad];

  LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil] autorelease];
  loginViewController.delegate = self;

  loginViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  [self presentModalViewController:loginViewController animated:YES];
}

- (void)loginViewControllerFinished {
  [self dismissModalViewControllerAnimated:YES];

  // Here we are closing one modal. And showing another after that.
  ABPeoplePickerNavigationController *peoplePicker = [[[ABPeoplePickerNavigationController alloc] init] autorelease];
  peoplePicker.peoplePickerDelegate = self;
  [self presentModalViewController:peoplePicker animated:YES];
}

LoginViewController:

// Make sure LoginViewController has delegate property in header.
// @property (nonatomic, assign) id delegate;
// And put this in implementation (.m) file. @synthesize delegate.
// Don't put release for delegate, since it not retained. It only 'assigned'.

- (void)done {
  // Call this when you want to close loginViewController.
  [delegate loginViewControllerFinished];
}

, .

+1

All Articles