在iPad上访问UIActionSheet的UIPopoverController

wes*_*der 16 uiactionsheet ipad uipopovercontroller

在iPad上,可以使用-showFromBarButtonItem:animated:来显示UIActionSheet.这很方便,因为它将UIPopoverController包装在操作表周围,并将弹出框的箭头指向传入的UIBarButtonItem.

但是,此调用将UIBarButtomItem的工具栏添加到直通视图列表中 - 这并不总是可取的.并且,如果没有指向UIPopoverController的指针,则无法将其他视图添加到直通列表中.

有没有人知道获得指向弹出控制器的指针的制裁方法?

提前致谢.

sta*_*kay 10

您需要调整方向更改.

我找到了另一种解决方案,对我来说非常适合.

依照

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

在你的@interface添加

UIActionSheet *popoverActionsheet;
Run Code Online (Sandbox Code Playgroud)

还添加

@property (nonatomic, retain) UIActionSheet *popoverActionsheet;
Run Code Online (Sandbox Code Playgroud)

还添加

- (IBAction)barButtonItemAction:(id)sender;
Run Code Online (Sandbox Code Playgroud)

因此,您可以从实施的任何位置参考您的操作表.

在你的实施中

- (IBAction) barButtonItemAction:(id)sender
{
    //If the actionsheet is visible it is dismissed, if it not visible a new one is created.
    if ([popoverActionsheet isVisible]) {
        [popoverActionsheet dismissWithClickedButtonIndex:[popoverActionsheet cancelButtonIndex] 
                                                     animated:YES];
        return;
    }

    popoverActionsheet = [[UIActionSheet alloc] initWithTitle:nil
                                                     delegate:self
                                            cancelButtonTitle:nil 
                                       destructiveButtonTitle:nil
                         otherButtonTitles:@"Save Page", @"View in Safari", nil];

    [popoverActionsheet showFromBarButtonItem:sender animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

在您的动作表委托实现中

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{

    if (buttonIndex == [actionSheet cancelButtonIndex]) return;

    //add rest of the code for other button indeces
}
Run Code Online (Sandbox Code Playgroud)

并且不要忘记在中发布popoverActionsheet

- (void)dealloc
Run Code Online (Sandbox Code Playgroud)

我相信这会做到.


nbr*_*sby 9

    if ([[[[actionSheet superview] superview] nextResponder] respondsToSelector:@selector(setPassthroughViews:)]) {
        [[[[actionSheet superview] superview] nextResponder] performSelector:@selector(setPassthroughViews:) withObject:nil];
    }
Run Code Online (Sandbox Code Playgroud)

如果没有调用任何私有API,这不应该导致App Reviewers出现任何问题.

它是脆弱的 - if语句确保你的代码不会崩溃(只是不工作)Apple不太可能发生改变底层实现的事件.


sta*_*kay 2

我认为这是不可行的。我也遇到了同样的问题。

使用

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

例子:

[actionSheet showFromRect:[[[myToolBar subviews] objectAtIndex:0] frame] inView:myToolBar animated:YES];
Run Code Online (Sandbox Code Playgroud)

注意:您必须更改 objectAtIndex: 的索引以适合您的情况并引用您的工具栏