1

私は、UIPreviewActions と共に、アプリに Peek と 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 から起動する必要があります。これを行うにはどうすればよいですか?

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 に答える