如何在popover中显示一个动作表?

时间:2010-05-17 09:37:29

标签: ipad controller action popover

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

2 个答案:

答案 0 :(得分: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 docs表示showFromRect:inView:animated:方法:

  

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

答案 1 :(得分:0)

我将此用于更多高级用途:

  1. 找到自定义accesoryView(cell.accesoryView)
  2. 如果为空,如果单元格
  3. ,则找到生成的accesoryView(UIButton)
  4. 如果UIButton不存在,找到单元格上下文视图(UITableViewCellContentView)
  5. 如果单元格竞争视图不存在,请使用单元格视图
  6. 可用于 UIActionSheet UIPopoverController

    这是我的代码:

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