簡體   English   中英

如何在按鈕操作上從UIView移動到UIViewcontroller

[英]How to move from UIView to UIViewcontroller on button action

我在UIView上有一個按鈕,想要在按鈕點擊時初始化一個UIViewcontroller 我試圖在按鈕單擊時顯示另一個ViewController ,但我收到錯誤:

reason:'[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()
    }
}

reason:'[setValue:forUndefinedKey:]:此類與密鑰AboutUser不符合密鑰值編碼。

回復:mab是你從另一個控制器復制粘貼按鈕請刪除該類的操作並為該類提供操作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM