Question

In my childview controller I have this property:

@property (nonatomic, assign) NSInteger currentItemIndex;

In parent view controller, I want to set that value.

    [childViewController setCurrentItemIndex:5];
    [self.navigationController pushViewController:childViewController animated:YES];

But in the childViewController, currentItemIndex is 0.

Why I cannot set it? Where am I wrong?

Was it helpful?

Solution

ReceiverViewController.h

@property (nonatomic, assign) NSInteger currrentIndex;

ReceiverViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"Index value %d",self.currrentIndex);
}

DataPassingViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.


     DataPassingViewController *detailViewController = [[DataPassingViewController alloc] initWithNibName:@"DataPassingViewController" bundle:nil];
    detailViewController.currrentIndex = 5;
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
}

I used the above code which gives a output as follows:

2013-07-10 17:50:10.230 DataPassing[3881:c07] Index value 5

OTHER TIPS

Try to read _CurrentIndex inside your childview class, this variable should be autogenerated and set using the setter setItemIndex method. I had too an experience with Xcode that when i did a build for 64 bit target, the internal variable with underscore was generated automatically, but for 32 bit target i had to declare it in interface and use the @synthesize statement in inplementation to get the code to compile.

Just declare simply, as

@property NSInteger currentItemIndex;

And if it dont solve the problem, you have to tell where you declare the property, which class, in interface declaration or not, which xcode you are using etc. post more code.

e.g. for xcode 4.6 this is okay. but for old xcode you have synthesize the property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top