How to show action sheet inside popover?

I have a split view controller that has a table view controller on the left side. How to show the action bar inside a popover when I click on the expand button of a table cell?

+7
ipad popover controller action
source share
2 answers

Try the following:

UIActionSheet *popupSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"No Way !" otherButtonTitles:nil]; popupSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; UIButton * disclosureButton = (UIButton *)cell.accessoryView; [popupSheet showFromRect:disclosureButton.bounds inView:cell.accessoryView animated:YES]; [popupSheet release]; 

UIActionSheet docs indicate that the showFromRect:inView:animated: method

displays the action sheet in a popover, the arrow of which points to the specified presentation rectangle (in our case, the disclosure button). Popsor does not overlap the specified rectangle.

+15
source share

I use this for more advanced use :

  • finds the user method accesoryView (cell.accesoryView)
  • if empty, find the generated accesoryView (UIButton) if the cell has
  • If UIButton does not exist, find the cell view (UITableViewCellContentView)
  • If the cell socket view does not exist, use the cell view

Can be used for UIActionSheet or UIPopoverController .

Here is my code:

 UIView *accessoryView = cell.accessoryView; // finds custom accesoryView (cell.accesoryView) if (accessoryView == nil) { UIView *cellContentView = nil; for (UIView *accView in [cell subviews]) { if ([accView isKindOfClass:[UIButton class]]) { accessoryView = accView; // find generated accesoryView (UIButton) break; } else if ([accView isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) { // find generated UITableViewCellContentView cellContentView = accView; } } // if the UIButton doesn't exists, find cell contet view (UITableViewCellContentView) if (accessoryView == nil) { accessoryView = cellContentView; } // if the cell contet view doesn't exists, use cell view if (accessoryView == nil) { accessoryView = cell; } } [actionSheet showFromRect:**accessoryView.bounds** inView:**accessoryView** animated:YES]; 

Tested in iOS 4.3 to 5.1

Best used as a custom method:

 -(UIView*)getViewForSheetAndPopUp:(UITableViewCell*)cell; 

And the method code:

 -(UIView*)getViewForSheetAndPopUp:(UITableViewCell*)cell { UIView *accessoryView = cell.accessoryView; if (accessoryView == nil) { UIView *cellContentView = nil; for (UIView *accView in [cell subviews]) { if ([accView isKindOfClass:[UIButton class]]) { accessoryView = accView; break; } else if ([accView isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) { cellContentView = accView; } } if (accessoryView == nil) { accessoryView = cellContentView; } if (accessoryView == nil) { accessoryView = cell; } } return accessoryView; } 
0
source share

All Articles