开发者

Iphone Pass an object (Button back on nav bar)

i have a question. How can i pass and object to the previous view when i press the back button in UINavigationBar?开发者_JAVA技巧


If you have a link to your view in your current VC like this :

previousVC.objectToPass = objectToPass;

Or with a notification like this :

1 - in your back method :

 [[NSNotificationCenter defaultCenter] postNotificationName:@"PassObject" withObject:objectToPass];

2 - In your previousVC :

- (void) didReceiveNotificationPassObject:(NSNotification*)notification  
{
    YourObjectClass *theObject = (YourObjectClass*)notification.object;
}

3 - In the init of your previousVC :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotificationPassObject:) name:@"PassObject" object:nil];


I am explaining with an example

there are two screens first and second.

Currently i m on second view.

so make a property of that object which you want to pass

MyObject *obj and make it property

@property(nonatomic,retain) MyObject *obj; in second.h

then set this in viewWillDisappear or wherever you want

make object of Second class

Second *objSecond=......;

then objSecond.obj is that object which you need on this page.now you can do whatever you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜