开发者

iphone UINavigation Controller

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 开发者_Python百科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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜