I posted a question earlier about the same thing, but now I have made a simple project to show what I am doing, so the problem can be found easier.
I have two viewControllers, one is called ViewController and the other SecondViewController. I tried sending a NSString called testy to a viewController and logging it, but it returned null.
Here is my code trying to send the string from viewController to secondViewController
ViewController.m
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize cellName;
- (void)viewDidLoad
{
[super viewDidLoad];
cellName = @"testy";
SecondViewController *obj = [[SecondViewController alloc] init];
obj.cellName2 = self.cellName;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
}
@property(nonatomic,retain) NSString *cellName;
@end
SecondViewController.m
#import "SecondViewController.h"
#import "ViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
@synthesize cellName2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
NSLog(@"%@",cellName2);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController {
}
@property(nonatomic,retain) NSString *cellName2;
@end
Edit
I would like to say that my storyboard has two viewController that each have a button. Each button modally brings you to the other view.