ios - 为什么 Xcode 不允许我使用 presentViewController?

标签 ios xcode swift sprite-kit

我想在我的 SpriteKit 游戏中实现一个分享功能。我有一个按钮,我正在尝试在 Gamescene 中执行此操作。这是我为此找到的代码:

func handleTwitter(sender: AnyObject) {
// Check if Twitter is available
if(SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter)) {
// Create the tweet
let tweet = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
tweet.setInitialText("I want to share this App: ")
tweet.addImage(UIImage(named: "shareImage"))
self.presentViewController(tweet, animated: true, completion: nil)

看起来很合乎逻辑,但我有问题

self.presentViewController(tweet, animated: true, completion: nil)

Xcode 告诉我 GameScene 没有名为“presentViewController”的成员。我是否只需要在 GameViewController.swift 中实现此代码?如果是这样,我将如何在游戏场景和其他场景中使用它?我有两个带有共享按钮的场景。或者问题出在 SLComposeViewController 中?我不明白问题出在哪里,我是否需要在 GameScene 中声明某种委托(delegate)才能使其正常工作?

最佳答案

这是适合我的代码。

UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController:tweet animated:YES completion:nil];

希望对你有帮助

关于ios - 为什么 Xcode 不允许我使用 presentViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875650/

相关文章:

ios - 当我的应用程序处于后台时,如何确保在使用 AV Foundation 时我的媒体将继续播放?

swift - 可扩展的表格单元格内容从单元格溢出

ios - flutter 项目未在 ios 上运行

ios - "unable to dequeue a cell with identifier"当切换到编程转换而不是 segue 时

ios - 在 layoutSubviews() 内部设置子层的框架使得无法更改它。有什么解决方法吗?

ios - 工作区包括 pod 安装和成功构建后丢失的文件

ios - 画一个半圆按钮iOS

ios - IONIC 2 - 每次打开应用程序时都会询问地理位置或获得许可

ios - Audiokit 4.5.2 - 无法通过终端中的 cocoa pod 安装

iphone - 应用内购买显示警告在 iTunes 连接中的应用内不可用