bodacious
bodacious

Reputation: 6705

iOS - How can I show a UIImagePicker over a UITableView?

I have a table cell which, when selected, should allow the user to select an image from photo library or take a new image.

The screen structure is:

UITabBar -> UINavigationController -> ParentController -> MyController

The code to achieve this in MyController is

- (void)showPhotoMenu
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:nil
                                  delegate:self
                                  cancelButtonTitle:@"Cancel"
                                  destructiveButtonTitle:nil
                                  otherButtonTitles:@"Take Photo", @"Choose From Library", nil];

        [actionSheet showInView:self.view];
    } else {
        [self choosePhotoFromLibrary];
    }
}

When tapping the cell, I get the option to choose from Library or take a photo but nothing seems to happen after that. The log output shows

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

But I'm not sure that's why the ImagePicker screens (photo library or camera) won't display.

From what I gather, that's warning that the cancel button won't be accessible because the tab bar covers it?

Can anyone advise where I might be going wrong here?

Upvotes: 0

Views: 447

Answers (1)

Paulo
Paulo

Reputation: 1245

There is not enough of the code to say for sure but the

Action Sheets uses your code as a delegate and returns control to you in a fixed delegate method

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  if (buttonIndex == actionSheet.firstOtherButtonIndex + 0) {
    //code to take photo
  } else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1) {
    //code to take access media
  } 
}

The other warning message - Do you or do you not see all options in your action sheet?

[actionSheet showInView:self.view]; 

There are a few more options depending on if you have a navigation bar or a Tab bar, I have an iPhone program with more Action Sheet choices than you and I never get the error.

Upvotes: 1

Related Questions