简体   繁体   中英

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.

It looks like you renamed your Button function to portal after you wired up the button.

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 .

在此处输入图片说明

Then drag from the circle next to Touch Up Inside to your portal function.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM