【发布时间】:2020-10-03 22:26:06
【问题描述】:
在处理一些包含登录功能的 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"
我可以请你写信给我这个问题的原因吗?
谢谢
【问题讨论】:
-
您的目标选择器被定义为具有一个参数(发送者)。你的实现没有。
-
@Phillip Mills 它有参数,刚刚编辑和添加。