【问题标题】:How to move from UIView to UIViewcontroller on button action如何在按钮操作上从 UIView 移动到 UIViewcontroller
【发布时间】:2018-12-10 14:04:09
【问题描述】:

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

【问题讨论】:

  • 检查你的故事板连接
  • 检查您的插座并确保所有插座仅与您查看的视图控制器相关,而不是任何其他视图控制器当您将视图复制到另一个视图控制器时可能会发生这种情况控制器
  • 是否有重复的出口请删除操作重新添加
  • TinderCard 中的委托是什么?你在哪里注册@objc func info_Btn_Action(sender: UIButton) 的手势。 SwipeViewControllerTinderCardDelegate 一致,但没有关于它委托给哪个元素的信息。请检查此stackoverflow.com/help/how-to-ask 并尝试提供与您的问题相关的尽可能多的代码。

标签: ios swift uiview uiviewcontroller


【解决方案1】:

reason: '[ setValue:forUndefinedKey:]: 这个类不符合关于键 AboutUser 的键值编码。'

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

【讨论】:

  • 你能分享故事出口截图吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-31
  • 2021-06-23
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
相关资源
最近更新 更多