iOS 7 custom UIActivity as popover
Asked Answered
F

0

2


This is my first question on StackOverflow, so please be patient with me...

Here's the problem:
I have created a custom Activity for adding bookmarks, which is opened from the UIActivityViewController. On iPhone it is opened as a modal, which is ok. But on iPad I open the UIActivity in a Popover, and I want the custom BookmarkActivity also to be opened in this Popover.
The method

-(UIViewController *)activityViewController in my UIActivity subclass looks like this:

- (UIViewController *)activityViewController {

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;
        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        nav.modalInPopover = YES;
        //nav.modalPresentationStyle = UIModalPresentationFormSheet;
        nav.modalPresentationStyle = UIModalPresentationCurrentContext;

        return nav;
    } else {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;
        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        return nav;
    }
}

With this code, the bookmark controller is shown in the popover for about 0.2 sec and then the popover disappears. If I change the property nav.modalPresentationStyle from UIModalPresentationCurrentContext to UIModalPresentationFormSheet the bookmarkController is correctly shown, but in a normal popup.

I did some research already and I have found two links:
UIActivity activityViewController being presented modally on iPad instead of in popover
-[UIActivity activityViewController] is not presented in a UIPopoverController

Both of them suggest, that it's not possible at the moment, but somehow it must be possible - it works in Safari (also the "Add Bookmark" feature).

So the questions are:

  1. How to change this behavior of the custom view controller to be opened in popover correctly?
  2. If the only possibility at the moment is to open it as a normal popup, is there a way to resize it? I have tried changing the navigation controllers and the bookmarks controllers size and frame, but it's not working.

Edit: I have contacted Apple about this, and here's the solution:
The method -(UIViewContreoller *)activityController looks now like this:

-(UIViewController *)activityViewController
{
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        return nil;
    }
    else
    {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;

        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        return nav;
    }
}

And the code for the view in popover has been moved to the -(void)performActivity method:

-(void)performActivity
{
     if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        GlobalBookmarksAddViewController *bookmarkViewController = [self.parentController.storyboard instantiateViewControllerWithIdentifier:@"GlobalBookmarksAddViewController"];

        bookmarkViewController.openedDocument = self.openedDocument;
        bookmarkViewController.yAxis = self.yAxis;

        bookmarkViewController.parentActivity = self;

        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:bookmarkViewController];

        nav.modalInPopover = YES;
        nav.modalPresentationStyle = UIModalPresentationCurrentContext;

        // self.activityController is my own property set for the activity after the UIActivityViewController is created
        [self.activityController presentViewController:nav animated:YES completion:NULL];
    }
}
Freon answered 12/5, 2014 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.