如何通过按钮操作从UIView移至UIViewcontroller

时间:2018-07-02 10:56:14

标签: ios swift uiview uiviewcontroller

我在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()
    }
}

1 个答案:

答案 0 :(得分:0)

原因:“ [[setValue:forUndefinedKey:]:此类与键AboutUser的键值编码不兼容。”

回复:可能是您从其他控制器复制粘贴按钮,请删除该类的操作并为该类提供操作