[英]Opening a Link to Safari Using a Button Swift App Crashing?
I am creating an app that acts like my school website. 我正在创建一个行为类似于我的学校网站的应用程序。 I added a button that I want to link to their original website using this code.
我添加了一个按钮,希望使用此代码链接到其原始网站。
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.
}
}
After running the app and clicking the button the app crashes leaving the error. 运行该应用程序并单击按钮后,该应用程序将崩溃并留下错误。
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'
I am fairly new at programming using Swift so I am looking for all the help I can get. 我在使用Swift进行编程方面还很陌生,所以我正在寻找可以得到的所有帮助。
It looks like you renamed your Button
function to portal
after you wired up the button. 似乎在连接按钮后,您已将
Button
函数重命名为portal
。
To correct this, in the Storyboard, Control -click on your button and then remove the event for Touch Up Inside by clicking on the little x . 要解决此问题,请在情节提要中, 按住Control键并单击鼠标左键,然后单击小x来删除“ Touch Up Inside ”事件。
Then drag from the circle next to Touch Up Inside to your portal
function. 然后从“ Touch Up Inside”旁边的圆圈中拖动到
portal
功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.