1

I'm trying to add a custom UIActivity to a UIActivityController. When I click on the item, it presents the view controller I want it to, but when I finish with that view controller, the original UIActivityViewController is still there. My question is, how and where do I dismiss the activity view controller? This is the code in my custom UIActivity.

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems{
    self.activityTitle = @"Text Editor";
    self.activityType = @"TextEdit";
    self.activityImage = [UIImage imageNamed:@"Icon.png"];
    if (activityItems) return YES;
    else return NO;
}

- (void)prepareWithActivityItems:(NSArray *)activityItems{
    for (NSString *path in activityItems) {
        if ([path lastPathComponent]) {
            self.file = path;
        }
    }
}

- (UIViewController *)activityViewController{
    ACTextEditController *actec = [[ACTextEditController alloc] initWithFile:_file];
    return actec;
}

EDIT

I've tried doing this, and I know it is called because I tried logging something in it and it was called

- (void)activityDidFinish:(BOOL)completed{
    if (completed) {
        [self.activityViewController dismissViewControllerAnimated:YES completion:nil];
    }
}

however, it's still there when the view controller dismisses. Why?

Chris Loonam
  • 5,735
  • 6
  • 41
  • 63
  • could you be more expecific? or redraw the question? i didn't understand what you need. – Juan Munhoes Junior Apr 26 '13 at 01:00
  • The problem is that after I dismiss the view controller presented by the `UIActivity` object, the original menu (`UIActivityViewController`) is still showing. It's possible to dismiss it by clicking cancel, but I'd like it to be dismissed already. – Chris Loonam Apr 26 '13 at 01:03
  • Is this on iPad? There's a huge bug with UIActivityViewController on iPad when you supply your own `activityViewController` – matt Apr 26 '13 at 01:10
  • OK, then your controller should contain buttons that dismiss, and they must send `activityDidFinish:`. – matt Apr 26 '13 at 01:11

1 Answers1

2

Here's a working example:

http://www.apeth.com/iOSBook/ch26.html#_activity_view

Notice that we end up by calling activityDidFinish:. That is what tears down the original interface. It may be that that is the step you are omitting. If not, just compare what you're doing with what I'm doing, since what I'm doing works (on iPhone).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 2
    Because you are not doing what I said. – matt Apr 26 '13 at 02:25
  • Did you read the chapter I pointed you to? "it is not our job to present or dismiss the `activityViewController`. You just call the activity instance's `activityDidFinish` and everything is torn down for you. Just look at my example code! It shows you exactly what to do. – matt Apr 26 '13 at 02:28
  • I call `activityDidFinish:` when the view controller I present closes. I also tried calling it when a button is clicked in the activity view controller. I've noticed that when the view controller is presented after the button is clicked, the activity view controller dismisses, but when the view controller that I presented is dismissed, it comes back – Chris Loonam Apr 26 '13 at 02:28
  • You don't close it! You call `activityDidFinish` and everything is closed for you. – matt Apr 26 '13 at 02:28
  • This is a complete downloadable example: https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch26p758activityView – matt Apr 26 '13 at 02:30
  • Here is the activity: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch26p758activityView/ActivityViewTest/MyElaborateActivity.m – matt Apr 26 '13 at 02:31
  • Here is view controller: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch26p758activityView/ActivityViewTest/ElaborateViewController.m – matt Apr 26 '13 at 02:31
  • You don't present it. You don't close it. Your activity just hands the runtime the view controller (and the runtime presents it) and the view controller calls the activity's `activityDidFinish` when it's done (and the runtime dismisses everything). Read my chapter. Look at my code. I'm handing it to you on a plate. – matt Apr 26 '13 at 02:33
  • Wow I was overthinking this. Thanks for the help, it's fixed. – Chris Loonam Apr 26 '13 at 02:33
  • I couldn't get that sample code to work with a Storyboard. Is that a special case? – AaronG Aug 22 '13 at 17:35