任何类型的值 - >(0)没有成员isEnabled在迅速ios10

任何类型的值 - >(0)没有成员isEnabled在迅速ios10

问题描述:

为什么这是哈皮?我是新来的快速任何类型的值 - >(0)没有成员isEnabled在迅速ios10

我想record.isEnabled =假,但我得到这个错误,为什么?

值类型的任何 - >(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 
    } 
} 
+0

,你声明'record', –

+0

纪录是我的按钮。如果我单击按钮停止按钮我想设置要启用的记录按钮 – Tampa

+0

是否为您的按钮创建了iboutlet –

问题您连接在记录按钮@IBAction为@IBOutlet。解决这个问题拖动插座记录按钮从故事板并连接它与适当的文件。例如

@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 

    } 
}