Dan F
Dan F

Reputation: 17732

UIActionSheet not showing in popover

I have a table view, and when the user selects a particular row, I want to display a simple action sheet to select if the new entry will come from an existing contact, or create a new contact. I display the action sheet as such:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ( indexPath.row != 0  )
    {
        //Select the entry
    }
    else
    {
        UITableViewCell *selectedRow = [tableView cellForRowAtIndexPath:indexPath];
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"New Contact", @"Existing Contact", nil];

        [sheet showFromRect:selectedRow.frame inView:tableView animated:YES];
        return;
    }

    //Do some other stuff...

}

According to the documentation...

Discussion

On iPad, this method displays the action sheet in a popover whose arrow points to the specified rectangle of the view. The popover does not overlap the specified rectangle.

And yet...the action sheet shows up at the bottom of my view, instead of a popover to the side. The tableview is a master view in a splitviewcontroller

Any thoughts on why this doesn't work?

Upvotes: 2

Views: 1568

Answers (2)

PakitoV
PakitoV

Reputation: 2498

I was having the same issue and this answer help me:

Using UIActionSheet on iPad

if you show it from a UIBarButtonItem or UIToolbar that is already inside a popover it is then presented in a similar fashion as on the iPhone

The thing was for me that the table was showing int a split view and when on landscape that table was presented as a popover (lateral panel that you can hide with swipe), so once I turn the device to landscape the UIActionSheet starts showing in a popover. The reason is the one I put in bold: it cannot be show as a popover from inside another popover.

Upvotes: 1

Fernando Mazzon
Fernando Mazzon

Reputation: 3591

Instead of popping from the tableView, try converting the cell bounds to the topmost view (the controller's and pop it from there...

CGRect frame = [self.view convertRect:cell.bounds fromView:cell];
[sheet showFromRect:frame inView:self.view animated:YES];

Might be the case that there's more hierarchy inside the tableView and it's breaking your stuff.

Upvotes: 0

Related Questions