【问题标题】:Failed to set (titleText) user defined inspected property无法设置(titleText)用户定义的检查属性
【发布时间】:2020-11-02 00:26:51
【问题描述】:

我有一个 UIViewController,“MainViewController”-

class MainViewController: UIViewController {
    
    @IBOutlet weak var segmentControl: UISegmentedControl!
    @IBOutlet weak var userNameTextField: UITextField!
    @IBOutlet weak var passwordTextField: UITextField!
    @IBOutlet weak var controlButton: RoundedCornerButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
    
    @IBAction func switchBetweenSignInAndRegisterOption(_ sender: UISegmentedControl) {
        if sender.selectedSegmentIndex == 0{
            self.controlButton.text = "Sign In"
        }
        else{
            self.controlButton.text = "Register"
        }
    }
}

操作方法 - switchBetweenSignInAndRegisterOption(_:) 附加到 segmentControl 对象,当其 selectedSegmentIndex 更改时,我的 RoundedCornerButtontext 属性将更新。以下是 RoundedCornerButton 的代码-

class RoundedCornerButton: UIButton {
 
    var text: String = "Sign In"{
        didSet{
            setNeedsLayout()
        }
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.layer.borderWidth = 2.0
        self.layer.cornerRadius = (self.bounds.size.width * 0.025)
        self.layer.borderColor = UIColor.green.cgColor
        self.setTitle(text, for: .normal)
        self.titleLabel?.minimumScaleFactor = 0.50
       
    }
}

它在功能方面有效,但在控制台中显示以下错误。我不明白可能出了什么问题。

[ProjectName][12943:1296641] Failed to set (titleText) user defined inspected property on ([ProjectName].RoundedCornerButton): 
[<[ProjectName].RoundedCornerButton 0x7f8a13d0bd90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key titleText.

任何帮助将不胜感激。

【问题讨论】:

    标签: custom-controls ios13 swift5 key-value-coding


    【解决方案1】:

    我发现了这个问题,但我不知道它是如何留在我的故事板中的,因为我从 CustomButton 的代码中删除了 @IBInspectable。

    当我在我的代码甚至故事板用户界面中搜索并找不到titleText 时,我通过右键单击它转到我的故事板的源代码并选择源代码选项。令我惊讶的是,有以下代码 sn-p-

    <userDefinedRuntimeAttributes>
         <userDefinedRuntimeAttribute type="string" keyPath="titleText" value="Register"/>
    </userDefinedRuntimeAttributes>
    

    显然,即使我从代码中删除了@IBInspectable,它仍然保留在我的情节提要中。我删除了这部分,现在它可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      相关资源
      最近更新 更多