objective-c - ShareKit 模态视图 Controller 不会消失

标签 objective-c cocoa-touch uiviewcontroller modalviewcontroller sharekit

我在 Xcode 4.2 (iOS SDK 5) 上使用 ShareKit 0.2.1 在 Twitter 上分享文本。它共享正常,但在单击取消按钮(见下文)后成功共享后,模态视图 Controller 不会消失:

enter image description here

这是我的代码:

-(IBAction)shareOnTwitter:(id)sender{


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

    [SHKTwitter shareText:text];

}

我做错了什么?

最佳答案

这是 iOS 5 的问题。这是因为 ShareKit 在 UIViewController 上使用了一个名为 parentViewController 的方法,根据 Apple 文档,您不能再在 iOS 5 中使用它。相反,您必须使用 presentingViewController

因此,要在 ShareKit 代码中修复它,请进入 SHK.m,找到带有签名 (void)hideCurrentViewControllerAnimated:(BOOL)animated 的方法,并将其替换为:

- (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;
    }
}

这适用于 iOS 5。

关于objective-c - ShareKit 模态视图 Controller 不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7942990/

相关文章:

ios - 具有方言的字符串中的 NSRange

objective-c - 如何在我们键入时立即更改 NSTextField 的值?

iphone - 性能最高的音频层?

objective-c - iOS 在 session 期间保留 GPS 权限

iphone - 我的项目中使用的私有(private) API - 初学者

ios - 以编程方式添加的 ViewController 看起来已移动/转换(iOS、swift、 Storyboard)

iphone - 无论如何要延迟容器 View 中的嵌入式转场?

ios - 我如何将 swrevealview 作为第三个 View Controller ,如果我们将 swrevealview 作为初始 View Controller 其工作

objective-c - iOS - 旋转时 View 无法在 iPad 中正确加载

ios - 在 Swift 中为 UIPickerView 委托(delegate)方法