I have done this before but for some reason I am missing something. I am trying to push a new viewController on the stack while setting up some initial values.
The user selects a name from a UIPicker then then presses a UIButton. This button pushes a new VC on the stack and should display the name in a UILabel for now. When I use NSLog to verify my data I can see that the correct value for name is displayed. But ion the second VC the NSLog says it is 'null' which means not an object. I was expecting the value in VC2 to be initialized with the value from VC1 as VC2 was pushed on the stack.
I declare characterName and set a retain property for it, how can it be 'null'? I know I am over looking some detail but after hours of searching I thought I would ask for help.
VC1 Button code
VC2.h
VC2.m
The console result is this
EDIT: I am using Xcode 4.4 which I don't need to use @synthesize it seems
The user selects a name from a UIPicker then then presses a UIButton. This button pushes a new VC on the stack and should display the name in a UILabel for now. When I use NSLog to verify my data I can see that the correct value for name is displayed. But ion the second VC the NSLog says it is 'null' which means not an object. I was expecting the value in VC2 to be initialized with the value from VC1 as VC2 was pushed on the stack.
I declare characterName and set a retain property for it, how can it be 'null'? I know I am over looking some detail but after hours of searching I thought I would ask for help.
VC1 Button code
Code:
- (IBAction)continueButton:(id)sender {
NSString *name = [characterArray objectAtIndex:[charPicker selectedRowInComponent:pickerSelected]]; //pickerSelector is an int
MainVC *mainVC = [[MainVC alloc]init];
[mainVC setCharacterName:name];
[COLOR="Red"] NSLog(@"string 'name' is: %@", name);[/COLOR]
[self.navigationController pushViewController:mainVC animated:YES];
}
VC2.h
Code:
@interface MainVC : UIViewController{
NSString *characterName;
IBOutlet UILabel *charName;
}
@property (retain)NSString *characterName;
@end
VC2.m
Code:
@implementation MainVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
charName.text = characterName;
[COLOR="Red"] NSLog(@"characterName is: %@", characterName);[/COLOR]
}
return self;
}
@end
The console result is this
Code:
2012-07-31 00:27:38.211 XPm Tracker[12400:f803] characterName is: (null)
2012-07-31 00:27:38.212 XPm Tracker[12400:f803] string 'name' is: New Character
EDIT: I am using Xcode 4.4 which I don't need to use @synthesize it seems