Xcode4 从另一个viewController写入全局数组
我在一个viewController中有一个数组,我想从另一个viewController写入该数组,所以我将该数组定义为全局数组,但我没有成功写入它 ViewController1.hXcode4 从另一个viewController写入全局数组,xcode4,nsarray,global-variables,Xcode4,Nsarray,Global Variables,我在一个viewController中有一个数组,我想从另一个viewController写入该数组,所以我将该数组定义为全局数组,但我没有成功写入它 ViewController1.h extern NSArray *xArray; @property (nonatomic, retain) NSArray *xArray; NSArray *xArray; .. @property (nonatomic, retain) NSArray *xArray; .. @synthesize *x
extern NSArray *xArray;
@property (nonatomic, retain) NSArray *xArray;
NSArray *xArray;
..
@property (nonatomic, retain) NSArray *xArray;
..
@synthesize *xArray;
ViewController1.m
@synthesize xArray;
NSArray *xArray;
xArray = [[NSArray alloc] init];
#import "ViewController1.h"
NSArray *zArray = [NSArray arrayWithObjects:@"a",@"b",nil];
ViewController1.xArray = zArray;
NSArray *tmpArray1;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray1;
NSArray *tmpArray2;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray2;
ViewController2.m
@synthesize xArray;
NSArray *xArray;
xArray = [[NSArray alloc] init];
#import "ViewController1.h"
NSArray *zArray = [NSArray arrayWithObjects:@"a",@"b",nil];
ViewController1.xArray = zArray;
NSArray *tmpArray1;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray1;
NSArray *tmpArray2;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray2;
我得到以下错误:
在“ViewController1”类型的对象上找不到属性“xArray”找到解决方案,在应用程序委托中定义数组,并在任何类中使用它 AppDelegate.h
extern NSArray *xArray;
@property (nonatomic, retain) NSArray *xArray;
NSArray *xArray;
..
@property (nonatomic, retain) NSArray *xArray;
..
@synthesize *xArray;
ViewController1.m
@synthesize xArray;
NSArray *xArray;
xArray = [[NSArray alloc] init];
#import "ViewController1.h"
NSArray *zArray = [NSArray arrayWithObjects:@"a",@"b",nil];
ViewController1.xArray = zArray;
NSArray *tmpArray1;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray1;
NSArray *tmpArray2;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray2;
ViewController2.m
@synthesize xArray;
NSArray *xArray;
xArray = [[NSArray alloc] init];
#import "ViewController1.h"
NSArray *zArray = [NSArray arrayWithObjects:@"a",@"b",nil];
ViewController1.xArray = zArray;
NSArray *tmpArray1;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray1;
NSArray *tmpArray2;
AppDelegate *mainDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
mainDelegate.xArray = tmpArray2;