Reputation: 23
I'm learning Xcode with Udacity. I've met problems with exception error. Here's my ViewController.swift doc.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var recordingLabel: UILabel!
@IBOutlet weak var recordButton: UIButton!
@IBOutlet weak var stopRecordingButton: UIButton!
func buttonAction(sender:UIButton){
}
override func viewDidLoad() {
super.viewDidLoad()
stopRecordingButton.isEnabled = false
// Do any additional setup after loading the view.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("viewWillAppear called")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// depose of any resources that can be recreated
}
@IBAction func recordAudio(_ sender: AnyObject){
recordingLabel.text = "Recording in Progress"
stopRecordingButton.isEnabled = true
recordButton.isEnabled = false
}
@IBAction func stopRecording(_ sender: AnyObject) {
recordButton.isEnabled = true
stopRecordingButton.isEnabled = false
recordingLabel.text = "Tap to record"
}
}
and here is my AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
and my error message shows : Thread 1: Exception: "-[SingingScope_Storyboard.ViewController recordButton:]: unrecognized selector sent to instance 0x7fb12cc088c0"
What should I do to debug this? Thank you!
Upvotes: 1
Views: 1932
Reputation: 574
This can happen if you add a selector (a function connected to an event) through the storyboard and then change it in code, resulting in the storyboard being out of sync.
Assuming you're trying to connect buttonAction(sender:UIButton)
with your recordButton
, try doing this:
@IBAction func buttonAction(sender: UIButton)
If this doesn't work try providing some screenshots of your storyboard connections, I'll try to help out more!
Upvotes: 1