Reputation: 10245
Hi I am trying to pass an indexvalue from my parent view to my subview like this //main.m
SubViewController *subViewController = [[SubViewController alloc] init];
subViewController.parentViewSelectedIndexPath = indexPath;
However when I try to check to see if the value have been passed over to the subview like so
//sub.m
- (void)viewDidLoad
{
//
NSLog(@"%@", parentViewSelectedIndexPath);
//
decliration in side sub.h
//
@interface VehicleResultViewController : UITableViewController {
//
NSIndexPath *parentViewSelectedIndexPath;
//
@property (nonatomic, retain) NSIndexPath *parentViewSelectedIndexPath;
//
@end
//Answer
subview loads before it gets the indexpath being passed to is.. so I had to use a method that is executed later i.s.(didselectrowatindexpath) this printed out the correct indexpath that was sent to it from the main view.
it prints (null) to the console.. am I doing something wrong?
Upvotes: 2
Views: 197
Reputation: 112857
Add some NSLog
s to determine the order of calls, @Kevin makes the point that viewDidLoad
may be called prior to setting the property.
Also if the indexPath
is always set whenever subViewController
is instantiated it is good practice to create your own designated initializer with indexPath
as a parameter. In the case that @Kevin makes this is the answer.
Upvotes: 2