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; }
Pion
source share