FreaknBigPanda
FreaknBigPanda

Reputation: 1127

Cannot Dismiss Modal View Controller

I'm having a problem getting my modal view controller to properly display and then dismiss. Basically I have a modally displayed login window and I want to dismiss it after all the data that I want to display is loaded from the database. if I call

[self dismissModalViewControllerAnimated:YES] from within the LoginViewController class it works perfectly fine but if I call

[[mainController modalViewController] dismissModalViewControllerAnimated:YES] from within my datamanager class after I have successfully imported the data nothing happens. Which is extremely confusing because [mainController modalViewController] points to the locationManager class.

Does anybody have any ideas as to why this isn't working? I'm programming for iOS 4 if that matters.

Thanks!

Upvotes: 0

Views: 3978

Answers (3)

hypercrypt
hypercrypt

Reputation: 15376

The proper way to dismiss a modal view controller is to call -dismissModalViewControllerAnimated: on the view controller that presented it. Thus it should be [_splitViewController dismissModalViewControllerAnimated:YES];.

From your comment, you need to call -dismissModalViewControllerAnimated: on the main thread, you can do this like so:

dispatch_async(dispatch_get_main_queue(), ^{
    [_splitViewController dismissModalViewControllerAnimated:YES];
});

Upvotes: 3

FreaknBigPanda
FreaknBigPanda

Reputation: 1127

OK So I figured this out. Basically what was happening was that the [self dismissModalViewController] call was happening on another thread which for whatever reason means that the object did not properly process the dismiss message. I ended up using a notification and then called dismissModalView controller like so:

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

- (void)receiveDismissNotification:(NSNotification *) note
{
    [self performSelectorOnMainThread:@selector(dismissSelf) withObject:nil waitUntilDone:NO];
}

which works

Upvotes: 3

Rahul Chavan
Rahul Chavan

Reputation: 510

To close the Model View Controller use following code

[self dismissModalViewControllerAnimated:YES];

This code works with ios 5 also.

For presenting the model view controller

if (self.viewController!=nil)
{
       //sanity check for view controller
       [self.viewController SOMEVIEW animated:YES];
}

Upvotes: 1

Related Questions