Obj-C :从导航控制器中的detailViewController传回参数
您好,我正在 iPhone 应用程序上使用导航控制器。当我将控制器推入导航堆栈时,我能够向前传递数据,但是当我弹出控制器时如何将数据传递回来。
我基本上想要实现的是根导航控制器视图显示许多可以编辑的字段。然后,用户单击要编辑的字段之一,然后将带有用户想要编辑的字段名称的 EditViewController 推送到堆栈上。现在,用户输入字段的新值并按“保存”以弹出视图控制器。那么如何将 editViewController 中的值返回到根导航控制器视图呢?
Hi I am using a navigation Controller on an iPhone app. I am able to pass data forward when I push a controller into the navigation stack but how do I pass data back when I pop the controller.
What I am basically trying to achieve is the root navigation controller view displays a number of fields that can be edited. A user then clicks on one of the fields to be edited and a EditViewController is pushed onto the stack with the name of the field the user wants to edit. Now the users enters the new value of the field and presses save to pop the view controller. So how do I get the value from the editViewController back to the root navigation controller view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法:
EditViewController
时,将其传递给要修改的值的指针,而不是值本身。这样,控制器可以在弹出之前通过指针修改该值。EditViewControllerDelegate
协议。如果随后将其自身作为参数传递给EditViewController
,则EditViewController
可以调用适当的委托方法来通知根视图控制器任何更改。第一个最简单,第二个更灵活。
There's a couple of approaches:
EditViewController
, pass it a pointer to the value to be modified, not the value itself. That way, the controller can modify the value through the pointer before it is popped.EditViewControllerDelegate
protocol. If it then passes itself as a parameter to theEditViewController
, theEditViewController
can call appropriate delegate methods to inform the root view controller of any changes.The first is simplest, the second the more flexible.