1

我正在我的应用程序中实现 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 中启动。我该怎么做呢?

4

1 回答 1

5

您可以通过Protocol或来实现这一点NSNotification。您需要从方法中调用控制器(TableView 控制器)displayComposerSheet方法。

协议示例:

1 - 在 PreviewController 中创建协议:

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

2 - 在 PreviewController 中创建属性为:

@property (nonatomic, weak) id<PreviewControllerDelegate> delegate;

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

-(void) displayComposerSheet
{
    [self.delegate sendEmail];
}

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

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location

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

于 2016-02-20T08:49:24.927 回答