简体   繁体   中英

App Crashes after Button is Pressed

When my app loads, a microphone appears on the screen. When you tap the microphone a label that says "Recording" pops up along with a stop button. When you tap the stop button, the app crashes.

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var recordingInProgress: UILabel!
@IBOutlet weak var stopButton: UIButton!


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

override func viewDidAppear(animated: Bool) {
    //Hides the stop button
    stopButton.hidden = true
}


@IBAction func recordAudio(sender: UIButton) {
    //Shows the stop button
    stopButton.hidden = false

    //Shows the recording label
    recordingInProgress.hidden = false

    //TODO: Record Audio
    print("Recording in Progress.")

    }

This is my crash report:

Recording in Progress. Recording in Progress. 2015-10-20 15:44:48.247 Vex[1468:533404] -[Vex.ViewController stopButton:]: unrecognized selector sent to instance 0x14d5418a0 2015-10-20 15:44:48.253 Vex[1468:533404] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Vex.ViewController stopButton:]: unrecognized selector sent to instance 0x14d5418a0' * First throw call stack: (0x183be4f5c 0x1987dbf80 0x183bebc6c 0x183be8c14 0x183aecdcc 0x1891723c8 0x189172344 0x18915ac6c 0x189171c5c 0x18917188c 0x18916aac0 0x18913ba10 0x189139efc 0x183b9c5a4 0x183b9c038 0x183b99d38 0x183ac8dc0 0x18ec1c088 0x1891a2f44 0x1000322b0 0x1990068b8) libc++abi.dylib: terminating with uncaught exception of type NSException

Make sure that

@IBOutlet weak var stopButton: UIButton!

is connected on your storyboard to the actual button.

if you use storyBoard check the IBAoutlet connection , maybe you connect it twice to the class . please tell the result

you should check on storyboard/xib that your stop button Touch Up Inside Event is correctly linked with recordAudio action.

otherwise post your log.

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