Jonathan
Jonathan

Reputation: 2738

presentViewController after dismissViewControllerAnimated

I am trying to present a view controller (SLServiceTypeFacebook) after I dismiss a view controller. Like this

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    ////////////////////////////////////
    //Some Stuff Other Calculations//
    ////////////////////////////////////
    //Then

    if([SLComposeViewController isAvailableForServiceType: SLServiceTypeFacebook])
    {
        // Facebook Service Type is Available

        SLComposeViewController *slVC   =   [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];
        SLComposeViewControllerCompletionHandler handler    =   ^(SLComposeViewControllerResult result)
        {
            if (result == SLComposeViewControllerResultCancelled)
            {
                NSLog(@"Cancelled");

            }
            else
            {
                NSLog(@"Done");
            }

            [slVC dismissViewControllerAnimated:NO completion:Nil];
        };
        slVC.completionHandler = handler;
        [slVC setInitialText:post[@"user_fullname"]];
        [slVC addURL:[NSURL URLWithString:post[@"url"]]];

        [self presentViewController:slVC animated:NO completion:Nil];
    }

But this doesn't seem to work. The Facebook modal automatically cancels itself.

am I doing something wrong conceptually?

Upvotes: 1

Views: 4879

Answers (2)

Adnan Ertörer
Adnan Ertörer

Reputation: 23

Try this:

[self dismissViewControllerAnimated:NO completion:^{
    NewViewController *viewController = [[NewViewController alloc]initWithNibName:NSStringFromClass([NewViewController class]) bundle:nil];
    UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topRootViewController.presentedViewController)
    {
        topRootViewController = topRootViewController.presentedViewController;
    }

    [topRootViewController presentViewController:viewController animated:YES completion:nil];
}];

Upvotes: 0

Dev2rights
Dev2rights

Reputation: 3487

Use a completion block like so:

[self dismissViewControllerAnimated:NO completion:^{

   //SHOW YOUR NEW VIEW CONTROLLER HERE!
}];

Your missing your completion handler above.

Upvotes: 5

Related Questions