我正在创建一个类似我的学校网站的应用程序。我添加了一个按钮,我想使用此代码链接到他们的原始网站。打开链接到Safari使用按钮Swift应用程序崩溃?
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进行编程时相当新,所以我正在寻找所有我可以获得的帮助。
看起来你忘了加上'按钮:'函数来处理按钮事件。 – rmaddy