如何从UIActivity View Controller中选择的UIActivity项目中呈现ModalViewController? [英] How can I present a ModalViewController from a UIActivity item picked from UIActivity View Controller?

查看:84
本文介绍了如何从UIActivity View Controller中选择的UIActivity项目中呈现ModalViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在detailViewController中显示一些数据的应用程序。我在导航栏中有一个rightBarButton,它提供了一个UIActivityViewController,它充满了我自己的UIActivity子程序项。它们中的大多数工作正常,因为它们只是从详细视图中将一个小方面改变为数据,但我需要其中一个在选择时打开modalViewController。我一直从控制台收到以下警告......

I am working on an app that presents some data in a detailViewController. I have a rightBarButton in the navbar that presents a UIActivityViewController that is filled with my own UIActivity sublclassed items. Most of them work fine as they are just changing a small aspect to the data from the detail view, but I need one of them to open a modalViewController when selected. I keep getting the following warning from the console.....

    Warning: Attempt to present <UINavigationController: 0x1fd00590>  
on <UITabBarController: 0x1fde1070> which is already presenting <MPActivityViewController: 0x1fd2f970>

我想值得注意的是应用程序没有崩溃,但模态视图没有出现无论是。我假设UIActivityViewController本身是一个模态视图,你只能一次显示其中一个,所以任务是弄清楚在ActivityView消失后如何执行我的segue,但这就是我难倒的地方。我欢迎任何帮助,想法或反馈。我已经尝试了谷歌,但没有太多运气,我认为因为UIActivityViewController是如此新。

I suppose it is worth noting that the app doesn't crash but the modal view doesn't appear either. I am assuming that the UIActivityViewController is a modal view itself and you can only display one of those at a time so the task is to figure out how to perform my segue after the ActivityView has disappeared, but thats where I am stumped. I welcome any help, thoughts or feedback. I've tried google but haven't had much luck, I assume because The UIActivityViewController is so new.

这是我的设置到目前为止,
我的UIActivity对象具有设置为detailViewController的委托,用于自定义协议,该协议允许detailViewController执行数据更改,然后更新其视图。

Here is my setup so far, my UIActivity objects have a delegate set to the detailViewController for a custom protocol that lets the detailViewController perform the data changes and then update its view.

对于有问题的活动,应该提供modalView控制器我尝试过几种方法都会得到相同的警告。

for the activities in question that should present the modalView controller I have tried a few approaches that all get the same warning.

这些都不起作用!!!

1)只是尝试从我的委托方法执行segue

1) simply tried performing segue from my delegate method

- (void) activityDidRequestTransactionEdit
{
    NSLog(@"activityDidRequestTransactionEdit");
    [self performSegueWithIdentifier:@"editTransaction" sender:self];
}

2)尝试在UIActivityViewController上设置完成块并设置我的委托方法应该显示模态视图的bool标志(self.editor)

2)tried setting a completion block on the UIActivityViewController and having my delegate method set a bool flag that the modal view should be shown(self.editor)

[activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) {
    NSLog(@"completed dialog - activity: %@ - finished flag: %d", activityType, completed);
    if (completed && self.editor) {
        [self performSegueWithIdentifier:@"editTransaction" sender:self];
    }
}];

3)继承UIActivityViewController本身,给它作为委托的detailView,并覆盖它的dismissViewControllerAnimated:方法使用我自己的完成块

3) subclassing the UIActivityViewController itself, giving it the detailView as a delegate, and overriding it's dismissViewControllerAnimated: method with my own completion block

- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    [super dismissViewControllerAnimated:flag completion:^{
        [self.MPActivityDelegate activityDidRequestTransactionEdit];

    }];
}






工作解决方案

在UIActivity子类中,您需要覆盖此方法,如此

In the UIActivity subclass you need to override this method like so

- (UIViewController *) activityViewController {
    MPEditMyDataViewController *controller = [[MPEditMyDataViewController alloc] init];
    controller.activity = self; // more on this property below
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
    return navController;
}

$ MP
$ b

在MPEditMyDataViewController.h中(所选操作应生成的视图控制器)
您需要一个属性返回活动子类,如此

in your MPEditMyDataViewController.h (the view controller the chosen action should produce) You need a property back to the activity subclass like so

@property (strong, nonatomic) MPEditMyDataActivity *activity;

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
                                     initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                     target:self
                                     action:@selector(cancel)];

    self.navigationItem.leftBarButtonItem = cancelButton;
}
// here's how you dismiss the view controller when you are done with it
// after saving the changes to your data or whatever the view controller is supposed to do.
-(void) cancel
{
    NSLog(@"Cancel Button Pushed");
    [self.activity activityDidFinish:YES];
}
@end


推荐答案

做了更多的文档挖掘并发现这个方法用于UIActivity子类化

Did some more documentation digging and found this method for UIActivity subclassing

- (UIViewController *) activityViewController

它让我的视图控制器像我想要的那样从这里返回而不是试图从我的detailViewController中删除它。现在要弄清楚当我完成它时如何解雇它!!!!

it gets my view controller to pop up like I wanted by returning it from here instead of trying to segue it from my detailViewController. Now to figure out how to dismiss it when I'm done with it!!!!

这篇关于如何从UIActivity View Controller中选择的UIActivity项目中呈现ModalViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆