I've two view controllers say A & B
In A.h I am doing
{
int cId;
bool selected;
}
@property (readwrite) int cId;
In A.m I am doing
@synthesize cId;
- (void) viewWillAppear : (BOOL) animated
{
//It will only call if its popBacked
if(selected==YES) //I set it to YES some where in my A.m and its push to : B
{
selected=NO;
NSLog(@"%d",cId); //getting 0 (zero)
}
}
In B.m I am doing
#import "A.h"
- (void) sentBack : (int) cIdValue
{
A *obj=[A alloc] init];
obj.cId=cIdValue;
NSLog(@"%d",obj.cId); //Its print properly
[self.navigationController popViewControllerAnimated:YES];
}
My problem is, when I pop back its value changes and set to 0 (zero). So I can't access my correct cId. Why it is changes? What I am doing wrong? Any help, suggestion is helpful. Thanks in advance.
//Edited your code of B.m
#import "A.h"
- (void) sentBack : (int) cIdValue {
if([[self.navigationController viewControllers] count]>0) {
A *AViewCont=[[self.navigationController viewControllers] objectAtIndex:0];
AViewCont.cId=cIdValue;
[self.navigationController popViewControllerAnimated:YES];
}
}
Try this one may help you.