msmialko
msmialko

Reputation: 1619

When and how to dismiss UIActivityViewController

I create and present UIActivityViewController in my app with custom UIActivity items in it.

When I tap UIActivity icon, UIActivityViewController slides down and my modal view controller is presented. However, when I dismiss my VC, UIActivityViewController shows up.

How can I make it disappear and never shows up again when activity item is pressed?

Upvotes: 3

Views: 7437

Answers (3)

Skovie
Skovie

Reputation: 197

i found this by Ethan Huang

        [self presentViewController: activityController animated: YES completion:nil];



        activityController.modalPresentationStyle = UIModalPresentationPopover;
        UIPopoverPresentationController *popPC = activityController.popoverPresentationController;
        popPC.barButtonItem = saveBtn;
        popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;

read all about it here :

http://getnotebox.com/developer/uiactivityviewcontroller-ios-8/

Upvotes: 0

jx ch
jx ch

Reputation: 55

Let's say when Activity A is chosen from UIActivityVC, you want to present modal view controller M on your current view Controller C .

If you implement A's -(UIViewController*)activityViewController method, you need to call [A activityDidFinish] in your modal view controller M's dismiss method;

If you implement A's -(void) performActivity method, it's impossible to present modal view , because current view controller C is in the process of dismissing UIActivityVC .

I think the final solution is a bit tricky. My basic idea is to subclass UIActivityViewController and override -(void) viewDidDisappear method. Thus you can do whatever you like( i.e present your own modal view,or push a sequence of other view controllers) on your current view controller C.

Upvotes: 2

rmaddy
rmaddy

Reputation: 318874

You need to call the activityDidFinish: method on the chosen UIActivity.

From the docs for UIActivity activityDidFinish::

Discussion
This method dismisses the sharing interface provided by the UIActivityViewController object. If you provided a view controller using the activityViewController method, this method dismisses that view controller too.

You must call this method after completing the work associated with this object’s service. This is true regardless of whether you used the activityViewController or performActivity method to initiate the service. When calling the method, use the Boolean value to indicate whether the service completed successfully.

Upvotes: 2

Related Questions