UISegmentedControl - 在闭包中缺少返回,期望返回'UISegmentedControl'

时间:2016-10-11 18:44:40

标签: swift xcode return-value uisegmentedcontrol

我正在尝试在登录时切换时隐藏nameTextField并使其显示在Register上切换。我一直试图弄明白自己,但这就是我所拥有的。我已经把它归结为两个错误,它们是相同的。 Issue Navigator

lazy var loginRegisterSegmentControl: UISegmentedControl = {
    let sc = UISegmentedControl(items: ["Login", "Register"])
    sc.translatesAutoresizingMaskIntoConstraints = false
    sc.tintColor = UIColor.white
    sc.selectedSegmentIndex = 1

    switch sc.selectedSegmentIndex
    {
    case 0: self.nameTextField.isHidden = true
    case 1: self.nameTextField.isHidden = false
    default:
        break; 

    sc.addTarget(self, action: #selector(handleLoginRegisterChange), for: .valueChanged)
    return sc

    }
}

2 个答案:

答案 0 :(得分:0)

self.nameTextField.hidden = true

答案 1 :(得分:0)

lazy var loginRegisterSegmentControl: UISegmentedControl = {
    let sc = UISegmentedControl(items: ["Login", "Register"])
    sc.translatesAutoresizingMaskIntoConstraints = false
    sc.tintColor = UIColor.white
    sc.selectedSegmentIndex = 1

    switch sc.selectedSegmentIndex
    {
    case 0: self.nameTextField.isHidden = true
    case 1: self.nameTextField.isHidden = false
    default:
        break; 

    sc.addTarget(self, action: #selector(handleLoginRegisterChange), for: .valueChanged)
    return sc

    }
}()