iPhone UI导航控制器
我试图更好地理解 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您不在 .xib 之间传递数据,而是在视图控制器之间传递数据。
请发布更多与此问题相关的代码。假设您正在谈论
UITableView
行,那么您的应用程序在响应行上的点击而将视图推送/弹出到导航堆栈上时应该不会出现任何问题。同样,您希望在视图控制器而不是视图之间传递数据。您可以通过在视图控制器上创建属性来轻松完成此操作,然后在将视图控制器推入堆栈之前设置这些属性。我认为您已经通过您的
item1
属性做到了这一点。如果您使用标准的 UINavigationController 来控制导航堆栈,则当用户点击后退按钮时,您不需要自己执行任何操作来管理内存;
UINavigationController
类将负责释放视图控制器本身。First off, you don't pass data between .xibs, you pass data between view controllers.
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.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.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; theUINavigationController
class will take care of releasing view controllers itself.