类型any->(0)的值在swift ios10中没有成员isEnabled

时间:2017-08-14 04:16:41

标签: ios swift uibutton

为什么会这样?我是swift的新手

我想要record.isEnabled = false但是我收到此错误的原因是什么?

  

类型any->(0)的值没有成员isEnabled

代码:

import UIKit
import AVFoundation

class ViewController: UIViewController, AVAudioPlayerDelegate, AVAudioRecorderDelegate {
    var audioPlayer: AVAudioPlayer?
    var audioRecorder: AVAudioRecorder?

    @IBAction func record(_ sender: Any) {
    }

    @IBAction func stop(_ sender: Any) {
       record.isEnabled = true
    }
}

1 个答案:

答案 0 :(得分:2)

问题是您已连接@ IBAction 中的记录按钮而不是 @IBOutlet 。要解决此问题,请从故事板中拖出 outlet 记录按钮,并将其与正确的文件相关联。

例如。

@IBOutlet weak var record: UIButton! // create the property for your button 

完整代码

import UIKit
import AVFoundation
class ViewController: UIViewController, AVAudioPlayerDelegate, AVAudioRecorderDelegate {

    var audioPlayer: AVAudioPlayer?
    var audioRecorder: AVAudioRecorder?

    @IBOutlet weak var record: UIButton!


    @IBAction func record(_ sender: UIButton!) {

        sender.isEnabled = false

    }
    @IBAction func stop(_ sender: Any) {

       record.isEnabled = true

    }
    @IBAction func play(_ sender: Any) {

    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
      record.isEnabled = true  

    }
}