view1.h
#import “view2.h"
@interface ViewController : UIViewController
{
int count;
}
@property (nonatomic, assign) int count;
in view1.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"rating"])
{
NSLog(@"identifier: help %@ \n",segue.identifier);
view2 *vc = [segue destinationViewController];
vc.imageNumber = &(count);
}
}
in view2.h
#import “view1.h"
@interface view2 : UIViewController
@property (nonatomic) int *imageNumber;
in view2.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"imagenumber %@\n",imageNumber);
}
What is wrong here? Ideally I want to be able to send the info both ways… but I’m just trying to figure out what’s wrong with the one way transfer. Thanks.
You check the int you set in
viewDidLoad.viewDidLoadhas already happened by the time you are inprepareForSegue. Try changing to useviewWillAppearorviewDidAppearand see what happens then. I think it should all work.EDIT
Sorry i didn’t look at your
NSLogclosely enough.%@in a format string, like what you use inNSLogis a stand in for anNSString, assumes the argument is anNSObjectand tries to call[imageNumber description]which is obviously nonsensical in this case. In fact you need to use the standard integer marker in the format string and then dereference the pointer. The correct NSLog statement would look like this: