开发者

Passing data between stacked views

In my app, I've several views.. and some of these views are pushed and popped using the navigation controller. In some view, I have a table view, in which each one of its cells is a view itself, so when the cell is selected, this code is executed :

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detail开发者_C百科view" bundle:nil];
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];

and in the detailview this code will be executed, when a specific button is clicked (e.g. back/cancel button):

[self.navigationController popViewControllerAnimated:YES];

What I want is passing data from the detailview to the view that precedes it(the view that initialize it). So far, I've implemented a class named "Globals.h", in which I put the data I want to pass, and uses "extern" on these data variables to ensure it'll be global to many classes, and it worked properly. But I don't feel that this is the appropriate way to do so. Is there any other good ways to do that ?

Thanks in advance :)


One easy way to solve it is:

DetailView *detailViewController = [[Detailview alloc] initWithNibName:@"Detailview" bundle:nil];
detailViewController.controller = self;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

and then in the detail view:

self.controller.data = data;
[self.navigationController popViewControllerAnimated:YES];

I hope you know how to create properties, otherwise drop me a comment.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜