I have a property that gets set when initiating a new view controller.
- (IBAction)headerPressed:(UIButton *)sender {
RouteViewController *route = [[RouteViewController alloc] initWithRoute:[[Route getRoute:TEST_ROUTE] autorelease]];
[[self navigationController] pushViewController:circle animated:NO];
}
in the new view, which is a UIViewController
RouteViewController.h
@interface =RouteViewController : UIViewController <MKMapViewDelegate> {
Route *r;
}
-(id)initWithRoute:(Route *)route;
@property (retain, nonatomic) Route *r;
RouteViewController.m
-(id)initWithRoute:(Route *)route{
self = [super init];
r = route;
return self;
}
- (void)loadView {
[super loadView];
NSLog(@"TEST: %d", r.Route); // throws exception. Actually ANY time I access my r property
}
r.Route is the int value that the const TEST_ROUTE contains.
NOW, when I setup my breakpoint, AT the time of the NSLog, the inspector shows my object contains
Self >
r >
Route: 1
and
r >
Route: 1
So the property is available, and it DOES contain the correct data. But when i try ACCESSING the property, it throws an EXC_BAD_ACCESS.
Thoughts? 🙂 (This is killing me here!)
There are a few problems here:
RouteViewController *route = [[RouteViewController alloc] initWithRoute:[[Route getRoute:TEST_ROUTE] autorelease]];I think the autorelease message should be sent to the
RouteViewControllerhere and not theRouteobject, as thegetRoutemethod should return an autoreleased object due to the naming convention.i.e.
You need to retain ownership of the Route object passed into the
initWithRoutemethod:Either:
or: