iPhone - 我已经更改了 XIB FileOwner,但它不断命中原始文件所有者中的方法

发布于 2024-12-10 20:35:32 字数 391 浏览 0 评论 0原文

所以...

  1. 我有一个 HomeViewController 和一个 IBAction DoStuff。
  2. 我有一个 XIB,其文件所有者为 HomeViewController,其中包含 正确调用 DoStuff 的按钮;

  3. 然后创建一个 NewViewController,将 DoStuff 方法复制到其中。

  4. 在 XIB 中,我将文件所有者的类更新为 NewViewController,删除并重新添加按钮的操作 对于DoStuff。

但是...按钮仍在从 HomeViewController 调用 DoStuff。

还有其他地方我需要删除这个引用吗?

非常感谢,

R

So...

  1. I have a HomeViewController, with an IBAction DoStuff.
  2. I have a XIB that has a File Owner of HomeViewController, which contains
    button that correctly calls DoStuff;

  3. Then created a NewViewController, copying the DoStuff method into it.

  4. Within the XIB, I then updated the Class of the File Owner to
    NewViewController, and deleted and re-added the action to the button
    for DoStuff.

BUT... the button is still calling DoStuff from HomeViewController.

Is there somewhere else I need to remove this reference??

Thanks very much,

R

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写下不归期 2024-12-17 20:35:32

您确定正在从正确的控制器加载 nib 文件吗?请注意,“文件所有者”只是 nib 文件中的占位符,它必须是在代码中创建的;除了文件所有者中的“类名”之外,IB 仅需要提供对其 IBAction 和 IBOutlet 的引用,但您需要确保在代码中正确加载它。

因此,如果在旧代码中您有类似的内容:


HomeViewController *myController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];

您必须将当前代码更改为:


NewViewController *myController = [[NewViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

在这种情况下,您将继续加载相同的 nib 文件,但所有对象都将被取消归档并分配给正确的文件所有者,即在代码。

请检查这一点,如果不起作用,请发布您的代码。

Are you sure you are loading the nib file from the right controller? note that "File's Owner" is just a placeholder in the nib file and it must have been created in code; besides the "class name" in File's Owner is only needed by IB to provide the references to its IBAction and IBOutlet but you need to ensure that you're loading it in code correctly.

So if in the old code you had something like:


HomeViewController *myController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];

you must change the current code as:


NewViewController *myController = [[NewViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

in this case you will keep loading the same nib file but all objects will be unarchived and assigned to the right file owner which is the one specified in the code.

Please check this point, if it's not working then post your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文