OGeek|极客世界-中国程序员成长平台

标题: ios - 将目标添加到另一个 View Controller 中的按钮 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:22
标题: ios - 将目标添加到另一个 View Controller 中的按钮

为什么这不起作用?我希望新 View Controller 中的 closeBtn 在当前 View Controller 中调用一个名为 dismiss: 的方法。

NewViewController *newVC = [[NewViewController alloc] initWithNibName"NewViewController" bundle:[NSBundle mainBundle]];

[newVC.closeBtn addTarget:self actionselector(dismiss forControlEvents:UIControlEventTouchUpInside];

dismiss: 方法永远不会在当前 View Controller 中调用。 closeBtn 已正确设置为 NewViewController 中的属性并链接到 .xib 文件中。



Best Answer-推荐答案


创建另一个 Controller 的对象并在 addTarget 中指定它。在 action 参数中给出方法的名称。 即另一个 Controller *obj; [button addTargetbj actionselector(MethodName) forControlEvents:UIControlEventTouchDown];

关于ios - 将目标添加到另一个 View Controller 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7828656/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4