[英]How to show an action sheet inside the popover?
I have a split View controller, in which the left side holds a table view controller. 我有一个拆分View控制器,左侧有一个表视图控制器。 How do I show an action sheet inside the popover when I click on the detail disclosure button of the table cell?
当我单击表格单元格的详细信息披露按钮时,如何在弹出窗口中显示操作表?
Try this : 试试这个 :
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];
The UIActionSheet docs state that the showFromRect:inView:animated:
method: UIActionSheet文档声明
showFromRect:inView:animated:
方法:
displays the action sheet in a popover whose arrow points to the specified rectangle of the view (in our case the detail disclosure button).
在弹出框中显示操作表,其中箭头指向视图的指定矩形(在我们的示例中为详细信息公开按钮)。 The popover does not overlap the specified rectangle.
弹出窗口不与指定的矩形重叠。
I use this for more advanced use: 我用这个用于更高级的用途:
Can be use for UIActionSheet or UIPopoverController . 可用于UIActionSheet或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 在iOS 4.3到5.1中测试过
Best to use as custom method: 最好用作自定义方法:
-(UIView*)getViewForSheetAndPopUp:(UITableViewCell*)cell;
And 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.