来自Peek的UIPreviewAction邮件
我正在努力在我的应用程序中实现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; }
displayComposerSheet只是编写电子邮件的标准方法,包括用于显示电子邮件的self presentViewController方法。 但是,所有这些方法都在PreviewController中,但Mail编写器在技术上需要从TableView启动所有这些。 我该怎么做呢?
您可以通过Protocol
或NSNotification
实现此目的。 您需要从displayComposerSheet
方法调用控制器(TableView控制器)方法。
协议示例:
1 – 在PreviewController中创建协议:
@protocol PreviewControllerDelegate - (void) sendEmail; @end
2 – 在PreviewController中创建属性:
@property (nonatomic, weak) id delegate;
3 – 从动作方法调用委托方法:
-(void) displayComposerSheet { [self.delegate sendEmail]; }
4 – 在UIViewControllerPreviewingDelegate
方法中加载之前设置PreviewController委托属性
- (UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location
5 – 在控制器(TableView Controller)中实现sendEmail
方法,您可以从中显示邮件编辑器。