I am trying to pass NSString value to another ViewController. But I get null instead of the value. Here is my code. FirstViewController.m:
NSString cellID = @"66";
SecondViewController *apiViewController = [[SecondViewController alloc] init];
apiViewController.strMessage=cellID;
[self.navigationController pushViewController:apiViewController animated:YES];
SecondViewController.h:
@interface SecondViewController : UIViewController{
NSString *strMessage;
}
@property(nonatomic,retain) NSString *strMessage;
@end
SecondViewController.m:
@implementation SecondViewController
@synthesize strMessage;
NSLog(@"%@", strMessage);
@end
I did import. I assigned variable before pushing. But it anyway returns null. How can I do this? Any tips, ideas. Thank you.
Try this
And Print
Try assigning the property before you push the view controller.
Furthermore, you need to call the
NSLog
from within a function in your implementation. TheviewDidLoad
function, for example, as this is a UIViewController that is being pushed on a UINavigationController stack.try this code