iPhone UI导航控制器

发布于 2024-09-19 11:22:57 字数 749 浏览 4 评论 0原文

我试图更好地理解 UINavigationController。我有 3 个 .xib。我从 .xib1 推送到 .xib2。我必须将数据从 .xib1 传递到 .xib2。

Controller1 *selectcity = [[Controller1 alloc]initWithNibName:@"Controller1" bundle:nil];   

selectcity.item1 = @"hi";
// Push the next view onto our stack
[self.navigationController pushViewController:selectcity animated:YES];
[selectcity release];

每次打开该视图时,我都需要将一些数据传递给 .xib2。每次用户在表中选择一行时将新视图推送到堆栈上,然后按“返回”,选择一行,返回,选择一行,返回,会非常快速地创建内存警告并终止应用程序。

如果我将视图添加为属性并检查它是否已存在,

if (xib2 == nil) {

}

则 viewDidLoad 方法仅在第一次调用视图时被调用,因此我无法将数据传递到表单。

我无法使用 viewDidAppear 等,因为我不想从 .xib3 返回时加载数据。

在这种情况下控制内存的正确方法是什么?每次他们按下后退按钮时,我是否应该从堆栈中弹出 xib2 ?是这样的话,我该用什么方法来做呢?

感谢您的帮助!

I'm trying to get a better understanding of the UINavigationController. I have 3 .xibs. From .xib1 I am pushing to .xib2. I have to pass data to .xib2 from .xib1.

Controller1 *selectcity = [[Controller1 alloc]initWithNibName:@"Controller1" bundle:nil];   

selectcity.item1 = @"hi";
// Push the next view onto our stack
[self.navigationController pushViewController:selectcity animated:YES];
[selectcity release];

I need to pass some data to .xib2 every time it opens that view. Pushing a new view onto the stack every time the user selects a row in the table, and then pressing back, selecting a row, back, selecting a row, back is creating a memoryWarning very quickly and killing the app.

If I add the view as a property and check if it already exists,

if (xib2 == nil) {

}

the viewDidLoad method only gets called the first time the view is called so I can't pass my data to the form.

I can't use viewDidAppear etc. because I don't want to the data to load when coming back from .xib3.

What is the correct way to control memory in this situation? Should I be popping xib2 from the stack every time they press the back button? Is so, what method would I do this?

Thanks for any help!

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

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

发布评论

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

评论(1

尬尬 2024-09-26 11:22:57

我正在努力变得更好
的理解
UINavigationController。我有 3 个
.xibs。从 .xib1 我正在推动
.xib2。我必须将数据传递给 .xib2
来自.xib1。

首先,您不在 .xib 之间传递数据,而是在视图控制器之间传递数据。

我需要将一些数据传递给.xib2
每次打开该视图时。推动
每次都有一个新的堆栈视图
用户在表中选择一行,
然后按返回键,选择一个
行,后,选择行,后是
非常快地创建内存警告
并杀死该应用程序。

请发布更多与此问题相关的代码。假设您正在谈论 UITableView 行,那么您的应用程序在响应行上的点击而将视图推送/弹出到导航堆栈上时应该不会出现任何问题。

viewDidLoad方法只获取
第一次调用该视图时
调用所以我无法将我的数据传递给
表格。

同样,您希望在视图控制器而不是视图之间传递数据。您可以通过在视图控制器上创建属性来轻松完成此操作,然后在将视图控制器推入堆栈之前设置这些属性。我认为您已经通过您的 item1 属性做到了这一点。

正确的控制方法是什么
在这种情况下记忆力如何?我应该是
每次都从堆栈中弹出 xib2
他们按下后退按钮?是这样的,
我会用什么方法来做到这一点?

如果您使用标准的 UINavigationController 来控制导航堆栈,则当用户点击后退按钮时,您不需要自己执行任何操作来管理内存; UINavigationController 类将负责释放视图控制器本身。

I'm trying to get a better
understanding of the
UINavigationController. I have 3
.xibs. From .xib1 I am pushing to
.xib2. I have to pass data to .xib2
from .xib1.

First off, you don't pass data between .xibs, you pass data between view controllers.

I need to pass some data to .xib2
every time it opens that view. Pushing
a new view onto the stack every time
the user selects a row in the table,
and then pressing back, selecting a
row, back, selecting a row, back is
creating a memoryWarning very quickly
and killing the app.

Please post more of the code related to this problem. Assuming you're talking about UITableView rows, your app shouldn't have any problems pushing/popping views onto the navigation stack in response to taps on rows.

the viewDidLoad method only gets
called the first time the view is
called so I can't pass my data to the
form.

Again, you want to pass data between view controllers, not views. You can do this quite easily by creating properties on your view controllers that you then set before you push the view controller on the stack. You are already doing this, I think with your item1 property.

What is the correct way to control
memory in this situation? Should I be
popping xib2 from the stack every time
they press the back button? Is so,
what method would I do this?

If you're using a standard UINavigationController to control the navigation stack, you don't need to do anything on your own to manage memory when the user hits the back button; the UINavigationController class will take care of releasing view controllers itself.

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