ios - 使用按钮打开 Safari 链接 Swift 应用程序崩溃?

标签 ios swift unrecognized-selector

我正在创建一个类似于我学校网站的应用程序。我添加了一个按钮,我想使用此代码链接到他们的原始网站。

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>.

enter image description here

然后从 Touch Up Inside 旁边的圆圈拖动到您的 portal 功能。

enter image description here

关于ios - 使用按钮打开 Safari 链接 Swift 应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33985038/

相关文章:

ios - Subview动画受mapview影响

ios - [NSNull 长度] : unrecognized selector sent to instance on keyboard keystroke?

ios - 在函数调用中发送到实例的无法识别的选择器

ios - 从服务器下载@2x 和@3x 图像到 Tableview

ios - 如何在 iOS 调试器中访问此变量?

ios - 在 swift 3 中显示来自自定义单元格的警报

iphone - NSFetchedResultsController 试图插入 nil 对象?

ios - 转换为 swift 3 后, View Controller 中出现奇怪的通用函数

ios - 如何正确配置 UITableView 自定义单元格

ios - NSCFNumber isEqualToString : crash IOS11 between viewDidLoad and viewWillApear