Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top