SOLUTION BELOW – Not really the problem I thought it was.
I’m adding data to the view controller that’s being segued into, using prepareForSegue:sender:, but my problem is that if the data is set using a property then that property is not changed. I can, however, use a private variable of the destination view controller, set using a function built for that purpose.
Here’s the code that works:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showLocationDetail"]) {
CityGuideFlipsideViewController *flipside = [segue destinationViewController];
CityGuideAnnotation *senderAnnotation = (CityGuideAnnotation *)sender;
[flipside annotate:senderAnnotation]; // why?
}
}
It seems much more natural, though, to use flipside.annotate = senderAnnotation than [flipside annotate:senderAnnotation].
Surely I must be doing something obvious here, but I can’t spot it.
EDIT to give the fail case more clearly:
// CityGuideFlipsideViewController.h
@interface CityGuideFlipsideViewController : UIViewController {
CityGuideAnnotation *annotation;
}
@property (strong, nonatomic) CityGuideAnnotation *annotation;
// CityGuideFlipsideViewController.m
@synthesize annotation;
- (void)setAnnotation:(CityGuideAnnotation *)_annotation
{
annotation = _annotation;
}
// CityGuideMainViewController.m (in prepareForSegue:sender)
CityGuideFlipsideViewController *flipside = [segue destinationViewController];
CityGuideAnnotation *senderAnnotation = (CityGuideAnnotation *)sender;
flipside.annotation = senderAnnotation;
On reaching the line assigning flipside.annotation as senderAnnotation the value of senderAnnotation is correct. flipside.annotation before assignment is nil. Following that line senderAnnotation is unchanged, flipside.annotation is unchanged.
BUT, reaching CityGuideFlipsideViewController viewDidLoad I have NSLog(@"%@",annotation.title) which spits out the correct value, even though the debugger still shows me nil for annotation.
So I’m really not sure if I previously had some minor error of if all along I’ve been fooled by annotation CityGuideAnnotation * 0x00000000 in the debugger.
Sorry about that, and thanks to those who helped.
Error was not in the code using a property. I was fooled by the debugger showing nil as the pointer. I’ll be more careful to log values in the future.
See edit on question above for more details.