gpt4 book ai didi

ios - 将目标添加到另一个 View Controller 中的按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:16 26 4
gpt4 key购买 nike

为什么这行不通?我希望新 View Controller 中的 closeBtn 调用当前 View Controller 中名为 dismiss: 的方法。

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

[newVC.closeBtn addTarget:self action:@selector(dismiss:) forControlEvents:UIControlEventTouchUpInside];

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

最佳答案

创建另一个 Controller 的对象并在 addTarget 中指定它。在 Action 参数中给出方法的名称。即 anotherController *obj;[按钮 addTarget:obj Action :@selector(MethodName) forControlEvents:UIControlEventTouchDown];

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com