Tometoyou
Tometoyou

Reputation: 8376

How to present UIImagePickerController from tab bar item

I have a UITabViewController. I'm trying to modally present a UIImagePickerController when a specific tab bar item is selected. It must appear over the current UIViewController. This is like what happens in the Instagram or Periscope app when you press on the camera icon. However I can't figure out how to display the UIImagePickerController without displaying the UIViewController that's connected to the Tab Bar Item. Is this possible?

Thanks,

Yusuf

Upvotes: 0

Views: 856

Answers (1)

DanielG
DanielG

Reputation: 2377

You can use the shouldSelectViewController method of UITabBarControllerDelegate to accomplish something like this.

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    // Check if it's the "image picker" tab
    if (viewController == self.imagePickerTabView) {
        // Present image picker
        return NO;
    }

    // All other cases switch to the tab
    return YES;
}

Upvotes: 2

Related Questions