xcode - 以编程方式“迅速”执行 segue
问题描述
我以编程方式在按钮中添加了“addTarget”属性以转到另一个视图控制器,但它不起作用。
login.addTarget(self, action: Selector(("toHome")), for: UIControl.Event.touchUpInside)
@objc func toHome(_ sender : UIButton!){
self.performSegue(withIdentifier: "Index", sender: self)
}
解决方案
Use the native selector syntax
login.addTarget(self, action: #selector(toHome), for: .touchUpInside)
and an implicit unwrapped optional as parameter is Swift 2 legacy syntax. Remove the exclamation mark
@objc func toHome(_ sender : UIButton) {
self.performSegue(withIdentifier: "Index", sender: self)
}
推荐阅读
- javascript - 网格项目框右侧的材质 UI 格式图标
- python - 在 Python 的嵌套函数中导入具有相同别名的模块
- c - libcurl 是否支持 RTSPS?
- wordpress - 在产品页面上,如何以编程方式设置变体值
- json - 如何在 kotlin + klaxon 上序列化到外部标记的枚举(多态类)?
- javascript - Google 表单:如何获取保存在数组中的表单响应项并在 JavaScript/Google App 脚本中传递给云系统的 POST 请求
- python - 对数据框中列的值进行计数和求和的条件函数
- python - ValueError: 层 lstm_1 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。收到的完整形状:(无,64)
- css - SVG 动画 onclick
- javascript - 如何根据页码从base64字符串pdf中获取页面内容 - 角度或javascript