我正在创建一个类似于我学校网站的应用程序。我添加了一个按钮,我想使用此代码链接到他们的原始网站。
import UIKit
class RearTableVC: UITableViewController {
@IBAction func portal(sender: AnyObject) {
let websiteAddress = NSURL(string: "http://www.google.com")
UIApplication.sharedApplication().openURL(websiteAddress!)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
运行应用程序并单击按钮后,应用程序崩溃并留下错误。
2015-11-29 11:10:45.554 FAQ[16888:2329672] -[FAQ.RearTableVC Button:]: unrecognized selector sent to instance 0x7fd0e857c6c0 2015-11-29 11:10:45.560 FAQ[16888:2329672] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FAQ.RearTableVC Button:]: unrecognized selector sent to instance 0x7fd0e857c6c0'
我对使用 Swift 进行编程还很陌生,所以我正在寻求所有我能获得的帮助。
最佳答案
在连接按钮后,您似乎将 Button
功能重命名为 portal
。
要更正此问题,请在 Storyboard 中,Control-单击您的按钮,然后通过单击小的 x< 删除 Touch Up Inside 的事件/em>.
然后从 Touch Up Inside 旁边的圆圈拖动到您的 portal
功能。
关于ios - 使用按钮打开 Safari 链接 Swift 应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33985038/