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 🙂
Check if you are resetting
newObjectsomewhere else likeinitmethod or so. Also change theNSLogtoNSLog(@"%@", self.newObject);and try again.