1

I presented a modal view where the presented view contains a tabbar controller.The view is displayed correctly,but when I add the dismissModalViewController to a button in tabbar viewController,it is not dismissing.Nothing is happening to the view.

How could I dismiss that modal view Controller?

1
  • How do you dismiss it? [self dismissViewControllerAnimated:NO completion: nil] is my best guess on this. note that you should use dismissViewController and presentViewController instead of ...ModalViewController since they are deprecated in iOS 5.1.
    – Tikkes
    Jun 8, 2012 at 7:31

3 Answers 3

2

The presenting view controller should be the one handling the dismissal of the modal view controller as well. You should use a delegate to notify the presenting view controller that it can dismiss the view controller it presented:

In the modal view controller:

@protocol SomeProtocol<NSObject>
- (void)didFinishDoingWhatItNeedsToDo:(id)sender;
@end

@interface ModalViewController : UIViewController
@property (nonatomic, weak) id <SomeProtocol> delegate;
@end

@implementation

- (IBAction)buttonClicked:(id)sender {

    [self.delegate didFinishDoingWhatItNeedsToDo:self];

}

Then in the presenting view controller:

@interface SomeObject : UIViewController <SomeDelegate>
@end

@implementation

- (void)someMethod {

    ModalViewController *mvc = [[ModalViewController alloc] init];
    mvc.delegate = self;

    [self presentViewController:mvc animated:YES completion:nil];
}

- (void)didFinishDoingWhatItNeedsToDo:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}
0

when you were presenting the controller with tabbar, you must have used :

[self presentModalViewController:newTabBarController animated:YES];

so when you want to dimiss you have to say,

[self.tabBarController dismissModalViewControllerAnimated:YES]
0
[[self parentViewController] dismissModalViewControllerAnimated:YES];
1
  • Why would you want to dismiss the parentViewController?
    – Tikkes
    Jun 8, 2012 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.