来自Peek的UIPreviewAction邮件

use*_*452 1 ios 3dtouch mfmailcomposeviewcontroller

我正在努力在我的应用程序中实现Peek和Pop,以及UIPreviewActions.我的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;
}
Run Code Online (Sandbox Code Playgroud)

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

小智 5

您可以通过实现这一目标ProtocolNSNotification.您需要从displayComposerSheet方法中调用控制器(TableView控制器)方法.

协议示例:

1 - 在PreviewController中创建协议:

@protocol PreviewControllerDelegate <NSObject>
- (void) sendEmail;
@end
Run Code Online (Sandbox Code Playgroud)

2 - 在PreviewController中创建属性:

@property (nonatomic, weak) id<PreviewControllerDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)

3 - 从动作方法调用委托方法:

-(void) displayComposerSheet
{
    [self.delegate sendEmail];
}
Run Code Online (Sandbox Code Playgroud)

4 - 在UIViewControllerPreviewingDelegate方法中加载之前设置PreviewController委托属性

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
Run Code Online (Sandbox Code Playgroud)

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