简体   繁体   English

Obj-C:从导航控制器中的detailViewController返回参数

[英]Obj-C : Passing parameters back from a detailViewController in a navigation controller

Hi I am using a navigation Controller on an iPhone app. 嗨,我在iPhone应用程序上使用导航控制器。 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. 然后,用户单击要编辑的字段之一,然后将EditViewController与用户要编辑的字段的名称一起推入堆栈。 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? 那么,如何从editViewController的值返回到根导航控制器视图?

There's a couple of approaches: 有两种方法:

  • When pushing your EditViewController , pass it a pointer to the value to be modified, not the value itself. 当推送您的EditViewControllerEditViewController传递指向要修改的值的指针,而不是值本身。 That way, the controller can modify the value through the pointer before it is popped. 这样,控制器可以在指针弹出之前通过指针修改该值。
  • Implement a delegation, where your root view controller implements an EditViewControllerDelegate protocol. 实现一个委派,您的根视图控制器实现一个EditViewControllerDelegate协议。 If it then passes itself as a parameter to the EditViewController , the EditViewController can call appropriate delegate methods to inform the root view controller of any changes. 如果然后将其自身作为参数传递给EditViewController ,则EditViewController可以调用适当的委托方法以将任何更改通知根视图控制器。

The first is simplest, the second the more flexible. 第一个最简单,第二个更灵活。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM