0
votes

In my app, you can add a photo using a modal view. When the modal view gets dismissed, I want to automatically switch the tab bar controller to the second tab (the photo viewer screen).

I found this answer about how to programmatically switch tabs, but I'm not sure where to put this code in the modal view controller.

1

1 Answers

3
votes

You can create a delegate protocol and assign a delegate property to the viewController being presented modally, and make it inform its delegate when it's about to call dismissModalViewControllerAnimated after taking a picture.

edit: added some more information about implementation

On the view controller class you are presenting modally, you would declare a protocol:

@protocol YourUIViewControllerSubclassDelegate;

Then, you would add a property to your class:

@property (nonatomic, unsafe_unretained)id <YourUIViewControllerSubclassDelegate>delegate;

finally, after your call the @end on your class interface declaration, you would complete the protocol:

@protocol YourUIViewControllerSubclassDelegate <NSObject>
- (void)viewController:(YourViewControllerSubclass *)viewController isBeingDismissedWithImage:(BOOL)imageTaken;
@end

So, inside your YourUIViewControllerSubclass, before calling dismissModalViewControllerAnimated, you would do:

[self.delegate viewController:self isBeingDismissedWithImage:YES or NO]; 

So, when you create YourUIViewControllerSubclass, you need to assign the delegate property. Whoever is the delegate of YourUIViewControllerSubclass needs to conform to the YourUIViewControllerSubclassDelegate protocol, and implement the protocol method. Inside this implementation of the protocol method, you would switch to whatever tab you would like to switch to.