7

我有一个拆分视图控制器,其中左侧包含一个表格视图控制器。当我单击表格单元格的详细信息披露按钮时,如何在弹出框内显示操作表?

4

2 回答 2

15

尝试这个 :

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 文档声明该方法showFromRect:inView:animated:

在弹出窗口中显示操作表,其箭头指向视图的指定矩形(在我们的示例中为详细信息显示按钮)。弹出框不与指定的矩形重叠。

于 2010-10-18T11:46:47.167 回答
0

我将其用于更高级的用途:

  1. 找到自定义的 accesoryView (cell.accesoryView)
  2. 如果为空,则查找生成的 accesoryView (UIButton) 如果单元格有
  3. 如果 UIButton 不存在,请查找单元格内容视图 (UITableViewCellContentView)
  4. 如果单元格内容视图不存在,请使用单元格视图

可用于UIActionSheetUIPopoverController

这是我的代码:

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];

在 iOS 4.3 到 5.1 中测试

最好用作自定义方法:

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

和方法代码:

-(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;
}
于 2012-06-19T19:50:33.857 回答