nithin
nithin

Reputation: 2467

Dismiss Modal View from uitabbarController view

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?

Upvotes: 1

Views: 1602

Answers (3)

Scott Berrevoets
Scott Berrevoets

Reputation: 16946

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];
}

Upvotes: 2

Shorhashi
Shorhashi

Reputation: 670

[[self parentViewController] dismissModalViewControllerAnimated:YES];

Upvotes: 0

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

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]

Upvotes: 0

Related Questions