我在UIView上有一个按钮,并希望在单击按钮时初始化一个UIViewcontroller。我试图在按钮单击上显示另一个ViewController,但我得到的错误如下:
原因:‘setValue:forUndefinedKey::这个类不符合键AboutUser的键值编码。’
// Protocol in UIView Class
protocol TinderCardDelegate: NSObjectProtocol {
func didInfoButtonTapped()
}
class TinderCard: UIView {
@objc func info_Btn_Action(sender: UIButton) {
print("tap")
delegate?.didInfoButtonTapped()
}
}
// Code in UIViewController
class SwipeViewController: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
}
func btninfoTapped() {
print("tappp")
let storyboard: UIStoryboard = UIStoryboard (name:
"UserProfileInfo", bundle: nil)
let vc: UserInfoViewController =
storyboard.instantiateViewController(withIdentifier:
"UserInfoViewController") as! UserInfoViewController
self.present(vc, animated: false, completion: nil)
}
}
extension SwipeViewController : TinderCardDelegate {
func didInfoButtonTapped() {
print("Button tapped ")
self.btninfoTapped()
}
}发布于 2018-07-02 11:05:33
原因:‘setValue:forUndefinedKey::这个类不符合键AboutUser的键值编码。’
答: mab是您从另一个控制器复制粘贴按钮,请删除该类的操作,并为该类提供操作。
https://stackoverflow.com/questions/51134557
复制相似问题