我正在与自己的UIPreviewActions一起在我的应用程序中实现Peek and Pop。我已经设置了我的PreviewView,并且Peek和Pop都很好用,我的问题是向其中添加UIPreviewActions。当然,您必须将UIPreviewAction方法放在预览控制器中,那么如何获取它然后关闭该视图,并在其父控制器中打开该视图?

我在PreviewController中:

- (NSArray*)previewActionItems {

    // setup a list of preview actions
    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Post to Facebook" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {


    }];

    UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Message" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {


    }];

    UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"Email" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
        [self displayComposerSheet];


    }];

    // add them to an arrary
    NSArray *actions = @[action1, action2, action3];

    // and return them
    return actions;
}

displayComposerSheet只是编写电子邮件的标准方法,其中包括用于显示电子邮件的self presentViewController方法。但是,所有这些方法都在PreviewController内,但是从技术上来说,邮件编辑器需要从所有位于其中的TableView启动。我应该怎么做呢?

最佳答案

您可以通过ProtocolNSNotification来实现。您需要从displayComposerSheet方法调用控制器(TableView控制器)方法。

协议示例:

1-在PreviewController中创建协议:

@protocol PreviewControllerDelegate <NSObject>
- (void) sendEmail;
@end

2-在PreviewController中创建属性为:
@property (nonatomic, weak) id<PreviewControllerDelegate> delegate;

3-从动作方法中调用委托方法:
-(void) displayComposerSheet
{
    [self.delegate sendEmail];
}

4-在将其加载到UIViewControllerPreviewingDelegate方法中之前设置PreviewController委托属性
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location

5-在控制器(TableView Controller)中实现sendEmail方法,从中可以显示邮件编写器。

关于ios - UIPreviewAction从窥视邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32997288/

10-14 19:58
查看更多