Reputation: 3685
I have a segue which when fired should have some data sent with it, so i have the below method set up:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *proFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleProTap:)];
[self.sharePost addGestureRecognizer:proFingerTap];
...
}
- (void)handleProTap:(UITapGestureRecognizer *)recognizer {
[self performSegueWithIdentifier:@"profileToPost" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"profileToPost"]) {
ProPostViewController *destViewController = segue.destinationViewController;
NSLog([NSString stringWithFormat:@"name:%@ id:%ld",_profileName,(long)_profileid]);
destViewController.profileid = _profileid;
destViewController.profileName = _profileName;
}
}
in the deist view controller i have the below in the header file:
@interface ProPostViewController : UIViewController <NSURLConnectionDelegate,NSURLConnectionDataDelegate>{
NSInteger profileid;
NSString *profileName;
}
@property (nonatomic) NSInteger profileid;
@property (nonatomic) NSString *profileName;
and then:
@implementation ProPostViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog([NSString stringWithFormat:@"name:%@ id:%ld",profileName,(long)profileid]);
if (profileid != 0){
[_postTitle setText:[NSString stringWithFormat:@"Posting to %@",profileName]];
}
// Do any additional setup after loading the view.
}
However the code is not passing the data as it should, from the two NSLogs which take place during this i get:
2015-08-11 10:48:53.653 APP[1705:119528] name:Alex id:3
2015-08-11 10:48:53.685 APP[1705:119528] name:(null) id:0
Upvotes: 0
Views: 34
Reputation: 89569
in your viewDidLoad
, change this line:
NSLog([NSString stringWithFormat:@"name:%@ id:%ld",profileName,(long)profileid]);
to this:
NSLog([NSString stringWithFormat:@"name:%@ id:%ld",self.profileName,(long)self.profileid]);
And if that works, get rid of the profileName
and profileid
ivars and leave the properties in place. If the compiler complains, use @synthesize
for the two properties.
Upvotes: 2