gpt4 book ai didi

ios - 从 Peek 到邮件的 UIPreviewAction

转载 作者:行者123 更新时间:2023-12-01 17:50:21 25 4
gpt4 key购买 nike

我正在我的应用程序中实现 Peek 和 Pop 以及 UIPreviewActions。我已经设置好 PreviewView,Peek 和 Pop 都很好用,我的问题是向其中添加 UIPreviewActions。当然,您必须将 UIPreviewAction 方法放在预览 Controller 中,那么如何让它关闭该 View ,并在其父 Controller 中打开该 View ?

我在 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 调用 Controller (TableView Controller )方法方法。

协议(protocol)示例:

1 - 在 PreviewController 中创建协议(protocol):

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

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

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

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com