从视图控制器调用函数 - 参数错误 - Swift2
问题描述:
我无法调用推文函数。我不断收到错误的参数。我也试过(AnyObject),并得到 错误:参数类型不符合预期...从视图控制器调用函数 - 参数错误 - Swift2
我是新来的迅速,不知道如何得到这个运行。尝试了我能想到的一切。谢谢
// 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)
答
尝试发送参数类型从AnyObject
改变UILabel
var vc = ViewController()
vc.tweetAction(yourUILabelInstance)
而且不要忘记修改tweetAction功能以及
@IBAction func tweetAction(sender: UILabel){
...
}
自我似乎在破解密码按钮。该行---------------->让skView = self.view as! SKView抛出错误“Thread1信号SIGARBT, –
什么是错误?是否有堆栈跟踪? –
错误”线程1:信号SIGABRT“断开的线是'let skView = self.view as!SKView',我配置view。控制台显示'无法将类型UIVIew的值转换为SKView,如果这个按钮是一个SKSpriteNode,那么这个按钮就是一个SKSpriteNode –