如何使用 popToViewController 发送字符串值

发布于 2024-11-17 08:44:13 字数 167 浏览 0 评论 0 原文

我正在使用导航控制器。我有(根,A,B,C,D)类。我想通过 popToViewController 将字符串 test 值 Class D 沙到 Class A

请给我建议。

谢谢

I am using navigationcontroller. i have (Root,A,B,C,D) class. i want to sand a string test value Class D to Class A via popToViewController.

Please give me suggestion.

Thanks

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

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

发布评论

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

评论(5

终止放荡 2024-11-24 08:44:13

UINavigationController< /code> 维护viewControllers< /code> 且根控制器始终位于 0

MyAController *myController = (MyAController *)[self.navigationController.viewControllers objectAtIndex:0];
myController.myText = @"My String" ;
[self.navigationController popToViewController:myController animated:YES];

UINavigationController maintain the list of all pushed controller in viewControllers and the root controller always reside at 0.

MyAController *myController = (MyAController *)[self.navigationController.viewControllers objectAtIndex:0];
myController.myText = @"My String" ;
[self.navigationController popToViewController:myController animated:YES];
笑看君怀她人 2024-11-24 08:44:13

您可能想重新考虑您的设计,但由于您没有提供足够的信息让我建议如何做,您可以尝试以下操作:

A *aController = (A *)[myNavController rootViewController];
[aController setMyString:@"your string here"];
[myNavController popToRootViewControllerAnimated:YES];

You might want to rethink your design, but since you haven't given enough information for me to suggest how, you could just try this:

A *aController = (A *)[myNavController rootViewController];
[aController setMyString:@"your string here"];
[myNavController popToRootViewControllerAnimated:YES];
纵性 2024-11-24 08:44:13

将该字符串作为类 a 的属性,然后您需要从类 D 的导航堆栈中访问视图 A 的该对象。

然后访问该属性以供使用。

如果 A 类是 rootView 那么 jtbandes 答案可以帮助您从堆栈代码中获取它,

if([self.navigationController.viewControllers count]>3)
             A *aController=(A *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-4];

如果您的导航是 A->B->c->D

那么您可以通过 [self.navigationController.viewControllers 访问 c计数]-2 类似地 B 乘 -3 A 乘 -4。

Make that string as property of class a then you need to access that object of the view A from navigation stack in class D.

And then access that property for using.

If Class A is rootView then jtbandes answers helps you otherwise pick it up from stack code some thing like this

if([self.navigationController.viewControllers count]>3)
             A *aController=(A *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-4];

if your navigation is A->B->c->D

then you can access c by [self.navigationController.viewControllers count]-2 similarly B by -3 A by -4.

鱼忆七猫命九 2024-11-24 08:44:13

有几种方法可以实现这一目标。

  1. 使用 通知
  2. 使用委托
  3. 使用 专卖店/酒店

There are several approaches to achieve this.

  1. Using Notifications.
  2. Using Delegates.
  3. Using Outlets/Properties.
栖迟 2024-11-24 08:44:13

您还可以在 ControllerB 中创建一个 ControllerA 实例变量,然后将 ControllerA (self) 传递给 ControllerB(例如:通过方法)在从 A 到 B 调用 pushViewController 之前。您可以从 B 到 C 执行相同的操作...等等;我认为最好的解决方案是 Jhaliya,以防您想使用 navigationControllers。

You could also create a ControllerA instance var in your ControllerB and then pass the ControllerA (self) to ControllerB(ex: by a method) before call pushViewController from A to B. You can do the same from B to C...etc; i think the best solution is that of Jhaliya in case you want to work with navigationControllers.

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