I’m trying to access some things from another viewcontroller (iOS).
I have my ViewController.h:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate> {
...
}
@end
ViewController.m:
#import "ViewController.h"
#import "ViewController2.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
ViewController2.someVar = @"cakes"; // this is where I'm trying to set something in vc2
}
ViewController2.h:
#import <UIKit/UIKit.h>
@interface ViewController2 : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate>
{
...
}
@property (nonatomic, copy) NSString *someVar;
@end
ViewController2.m:
#import "ViewController2.h"
@interface ViewController2 ()
@end
@implementation ViewController2
@synthesize someVar;
etc.
But at the line where I try to access this var, it gives me the following error:
Property ‘someVar’ not found on object of type ‘ViewController2’.
In what way would I achieve accessing this other view controller?
You have to create a
ViewControlle2object in yourViewcontroller.m.