I'm trying to pass data from 1 viewcontroller to another, but the NSString is getting lost somewhere. I apologize in advance, I feel like I'm missing something dumb here. I've read so many posts on this but I can't figure out why my NSStrings are getting lost between views. If anyone could give me a pointer I would really appreciate it:
ViewController1 passes payee.name to ViewController2 payeeNameText here:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"makePayment"]){
VC2* paymentController = (VC2*)[segue destinationViewController];
paymentController.payeeNameText = [payee.name copy];
}
}
ViewController2 tries to use that data to display the payees name in payeeName UILabel:
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@" test %@", self.payeeNameText);
self.payeeName.text = [NSString stringWithFormat:@"%@", self.payeeNameText];
}
Its prints it out correctly in the NSLog statement, but the text field displays as null. I also print out the same variable later after I click a button and its null there as well.
This is my definition of payee in View Controller 2 header file:
@property (nonatomic, copy) NSString *payeeNameText;
and my definition of the text field:
@property (nonatomic) IBOutlet UILabel *payeeName;
If I set paymentController.payeeNameText to a string literal such as @"test" - everything works as expected.
Please if anyone can help me, I've been stuck on this for a while, I would greatly appreciate it. Thank you!