ios - 无法打开 TableViewController
问题描述
在处理一些包含登录功能的 IOS 项目 (Swift5) 时,我遇到了一个奇怪的问题,即在按钮上单击一个新的 UITableViewController 打开,其中包含来自数据库的一些记录。奇怪,因为相同的功能在登录视图中没有任何问题,并且在用户登录后无法从视图中运行。
这是打开新控制器的方法:
@IBAction func didTapButton(sender: Any) {
// let story : UIStoryboard = UIStoryboard(name: "Main",
bundle:nil)
let categories = CategoriesTableViewController()
navigationController?.pushViewController(categories,
animated: true)
// let controller =
story.instantiateViewController(identifier:
"CategoriesTableViewController") as!
CategoriesTableViewController
//
// present(controller, animated: true)
}
这是我登录到此应用程序后单击运行上述方法时发生的错误:
Exception NSException * "-
[project7_4_adm.ViewController
didTapButtonWithSender:]: unrecognized selector sent
to instance 0x7f9889222260" 0x0000600001d35860
我在 google 中找到了一些解决方案,即向我所做的按钮添加目标:
btn.addTarget(self, action:
#selector(didTapButton(sender:)), for:
.touchUpInside)
但即使我这样做了,我也得到了一个错误:
Thread 1: "-
[project7_4_adm.CategoriesTableViewController
initWithIdentifier:source:destination:]: unrecognized
selector sent to instance 0x7fac3a11df90"
我可以请你写信给我这个问题的原因是什么?
谢谢
解决方案
异常原因清楚地表明将didTapButton(sender...
其转换为 Objective-C 为didTapButtonWithSender:
在IBAction
你必须插入一个下划线字符
@IBAction func didTapButton(_ sender: Any)
选择器可以很简单
#selector(didTapButton)
推荐阅读
- c# - 从 PropertyInfo 获取复杂类型属性
- java - Firebase 数据库检索未按顺序执行
- java - 带有输入 json 的 curl POST 命令,请求 Jersey 服务,给出 HTTP 415 错误
- r - R 官员包:哪个布局属性确定了唯一标识占位符的正确索引?
- python - OpenCV haar 分类器训练具有多个正图像
- c# - C#如何计算列表框选择的总和
- sql - TSQL 只选择最高的credentail
- arm - 在 aarch64 上运行 32 位精灵
- ansible - 在 Openshift 上使用带有多行机密的 Ansible Playbook Bundle
- node.js - jsftp - TypeError:createConnection 不是函数