gpt4 book ai didi

swift - 从 View Controller 调用函数 - 参数错误 - Swift2

转载 作者:行者123 更新时间:2023-11-30 13:20:24 24 4
gpt4 key购买 nike

我在调用 tweet 函数时遇到问题。我不断收到参数错误。我也尝试了 (AnyObject) 并得到了错误:参数类型不符合预期...

我是 swift 新手,不知道如何运行它。尝试了我能想到的一切。谢谢

   // from GameScene 
var vc = ViewController()
vc.tweetAction(sender: AnyObject)
//error: cannot create single-element tuple with an element label



//function in View Controller below

@IBAction func tweetAction(sender: AnyObject){

if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter){

let tweetController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)

tweetController.setInitialText("I Scored on this app")

self.presentViewController(tweetController, animated: true, completion: nil)
}
else{

let alert = UIAlertController(title: "Accounts", message: "Please log into your twitter to share", preferredStyle: UIAlertControllerStyle.Alert)

alert.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default, handler: nil))

alert.addAction(UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default, handler: { (UIAlertACtion) in

let settingsURL = NSURL(string:UIApplicationOpenSettingsURLString)

if let url = settingsURL{

UIApplication.sharedApplication().openURL(url)
}
}))
self.presentViewController(alert, animated: true, completion: nil)
}
}

最佳答案

您正在向方法调用传递类型而不是实例。您还包括第一个参数的标签,这是不正确的。尝试:

vc.tweetAction(self)

关于swift - 从 View Controller 调用函数 - 参数错误 - Swift2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37823140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com