Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShareKit modal view controller won't go away

I'm using ShareKit 0.2.1 on Xcode 4.2 (iOS SDK 5) to share text on Twitter. It shares fine, but the modal view controller wont go away after successfully sharing on after clicking on the cancel button (see below):

enter image description here

And this is my code:

-(IBAction)shareOnTwitter:(id)sender{


    // Item to share
    NSString *text = @"Go away, modal view controller!";

    [SHKTwitter shareText:text];

}

What am I doing wrong?

like image 976
cfischer Avatar asked Oct 30 '11 02:10

cfischer


People also ask

How do you dismiss a modal view controller?

According to the View Controller Programming guide for iPhone OS, this is incorrect when it comes to dismissing modal view controllers you should use delegation. So before presenting your modal view make yourself the delegate and then call the delegate from the modal view controller to dismiss.


1 Answers

I am having the same issue as you. It is an iOS 5 issue. It's because ShareKit is using a method on UIViewController called parentViewController and according to the Apple docs you can no longer use this in iOS 5. Instead, you must use presentingViewController.

So to fix it in the ShareKit code, go into SHK.m, find the method with signature (void)hideCurrentViewControllerAnimated:(BOOL)animated, and replace it with:

- (void)hideCurrentViewControllerAnimated:(BOOL)animated
{
    if (isDismissingView)
        return;

    if (currentView != nil)
    {
        // Dismiss the modal view
        if ([currentView parentViewController] != nil)
        {
            self.isDismissingView = YES;
            [[currentView parentViewController] dismissModalViewControllerAnimated:animated];
        } else if ([currentView presentingViewController] != nil) {
            self.isDismissingView = YES;
            [[currentView presentingViewController] dismissModalViewControllerAnimated:animated];
    } else
        self.currentView = nil;
    }
}

This works for me on iOS 5.

like image 147
Mike A. Avatar answered Sep 30 '22 14:09

Mike A.