bs7
bs7

Reputation: 627

Getting (null) while passing data between UIViewController

I'm confused. I have an UITableView and when I click on a row it performs a pushViewController with a new UIViewController. I want to pass data to this new view controller but my object is null. Here is the code I used :

//TableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    MyObject *myObject = [myArray objectAtIndex:indexPath.row];
    SecondViewController *vc = [[SecondViewController alloc] init];
    vc.newObject = myObject;
    [self.navigationController pushViewController:vc animated:YES];
}


//SecondViewController.h
@property (nonatomic, strong) MyObject *newObject;

//SecondViewController.m
@implementation SecondViewController
@synthesize newObject = _newObject;

- (void)viewDidLoad {
   NSLog(@"%@", _newObject);   // nil
}

That's strange because I always did things this way and it always worked before, I don't see why the returned value is null.

Thanks for your help :)

Upvotes: 1

Views: 510

Answers (1)

iDev
iDev

Reputation: 23278

Check if you are resetting newObject somewhere else like init method or so. Also change the NSLog to NSLog(@"%@", self.newObject); and try again.

Upvotes: 1

Related Questions