Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I see the question is quite old, but we've been debugging the same view-controller-not-dismissing issue here and I hope my answer will provide some additional details and a better solution than calling up <code>-dismissPopoverAnimated:</code> manually.</p> <p>The documentation on the UIActivity is quite sparse and while it hints on the way an implementation should be structured, the question shows it's not so obvious as it could be.</p> <p>The first thing you should notice is the documentation states you should <em>not</em> be dismissing the view controller manually in anyway. This actually holds true.</p> <p>What the documentation doesn't say, and what comes as an observable thing when you come across debugging the non-dissmissing-view-controller issue, is iOS <em>will</em> call your <code>-activityViewController</code> method when it needs a reference to the subject view controller. As it turns out, probably only on iPad, iOS doesn't actually store the returned view controller instance anywhere in it's structures and then, when it wants to dismiss the view controller, it merely asks your <code>-activityViewController</code> for the object and then dismisses it. The view controller instantiated in the first call to the method (when it was shown) is thus never dismissed. Ouch. This is the cause of the issue.</p> <p>How do we properly fix this?</p> <p>Skimming the <code>UIActivity</code> docs further one may stumble accross the <code>-prepareWithActivityItems:</code> method. The particular hint lies along the following text:</p> <blockquote> <p>If the implementation of your service requires displaying additional UI to the user, you can use this method to prepare your view controller object and make it available from the activityViewController method.</p> </blockquote> <p>So, the idea is to instantiate your view controller in the <code>-prepareWithActivityItems:</code> method and tackle it into an instance variable. Then merely return the same instance from your <code>-activityViewController</code> method.</p> <p>Given this, the view controller will be properly hidden after you call the <code>-activityDidFinish:</code> method w/o any further manual intervention.</p> <p>Bingo.</p> <p>NB! Digging this a bit further, the <code>-prepareWithActivityItems:</code> should <em>not</em> instantiate a new view controller each time it's called. If you have previously created one, you should merely re-use it. In our case it happily crashed if we didn't.</p> <p>I hope this helps someone. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload