如何在弹出窗口中显示操作表?

发布于 2024-09-02 03:52:25 字数 68 浏览 7 评论 0原文

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

I have a split View controller, in which the left side holds a table view controller. How do I show an action sheet inside the popover when I click on the detail disclosure button of the table cell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千仐 2024-09-09 03:52:25

试试这个:

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: 方法:

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

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:

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.

差↓一点笑了 2024-09-09 03:52:25

我将其用于更高级用途:

  1. 查找自定义accesoryView(cell.accesoryView)
  2. 如果为空,则查找生成的accesoryView(UIButton)如果单元格有
  3. 如果UIButton不存在,则查找单元格contet视图(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;
}

I use this for more advanced use:

  1. finds custom accesoryView (cell.accesoryView)
  2. if empty, find generated accesoryView (UIButton) if cell has
  3. if the UIButton doesn't exists, find cell contet view (UITableViewCellContentView)
  4. if the cell contet view doesn't exists, use cell view

Can be use 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 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文