在导航堆栈中传递变量?- 苹果手机 [英] Pass a Variable Up the Navigation Stack? - iPhone

查看:38
本文介绍了在导航堆栈中传递变量?- 苹果手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过将其视图控制器推到导航堆栈上,我能够将变量从视图控制器传递到视图控制器.我的操作方式示例如下:

I am able to pass a variable forward from view controller to view controller by pushing its view controller onto the navigation stack. An example of how I do it would be this:

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
controller.myString = stringToPass;
[self.navigationController pushViewController:controller animated:YES];
[controller release];

但是,如果我想传递一个变量到导航堆栈上怎么办?使用popViewControllerAnimated而不是pushViewController不会像我想的那样传递变量.

However, what do I do if I want to pass a variable BACK UP the navigation stack? Using popViewControllerAnimated rather than pushViewController does not pass the variable up like I thought it would.

我需要能够从定义它的视图控制器中访问几个弹出的变量.

I need to be able to access the variable several pops up from the view controller it is defined in.

任何帮助将不胜感激:)

Any help will be greatly appreciated :)

推荐答案

您正在传递值,而不是变量.

You're passing values, not variables.

视图控制器不应自行弹出.使用Apple的视图控制器(例如,UIImagePicker),父视图控制器负责执行弹出操作;父VC也可以获取当前值.(并非完全正确;在应用键盘自动补全功能之前,它可能会访问该值)

A view controller should not be responsible for popping itself. With Apple's view controllers (e.g. UIImagePicker), it is the parent view controller's responsibility to do the popping; the parent VC can also obtain the current value. (Not entirely correct; it might access the value before a keyboard autocompletion is applied)

或者,如果它是一个可以全局共享的值,则可以将其存储在应用程序委托中.

Alternatively, if it's a value that can be shared globally, you can store it in your application delegate.

这篇关于在导航堆栈中传递变量?- 苹果手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆