iphone,在类之间传递数组?

iphone,在类之间传递数组?,iphone,Iphone,我希望将数组从类A传递到类B,但A调用B。您需要设置的是简单的对象成员。实现这一点的最佳方法是使用属性: 在B.h中: @property(nonatomic,retain) NSArray * theArray_B; 在B.m.中: @synthesize theArray_B; 上午: myB_Instance.theArray_B = theArrayToPass; 在该示例中,A和B共享指向内存中相同数组对象的指针。此外,B拥有这个数组(A也拥有这个数组),因为它上面有一个ret

我希望将数组从类A传递到类B,但A调用B。

您需要设置的是简单的对象成员。实现这一点的最佳方法是使用属性:

在B.h中:

@property(nonatomic,retain) NSArray * theArray_B;
在B.m.中:

@synthesize theArray_B;
上午:

myB_Instance.theArray_B = theArrayToPass;
在该示例中,A和B共享指向内存中相同数组对象的指针。此外,B拥有这个数组(A也拥有这个数组),因为它上面有一个retain。

类似这样的东西:

A类包括:

- (void)someMethodInClassA {
    NSArray *arrayData = // ... stuff

    ClassB *classB = // ... stuff

    [classB aMethod:arrayData];

}
- (void)aMethod:(NSArray *)array {
    // do something with the array
}
B类包括:

- (void)someMethodInClassA {
    NSArray *arrayData = // ... stuff

    ClassB *classB = // ... stuff

    [classB aMethod:arrayData];

}
- (void)aMethod:(NSArray *)array {
    // do something with the array
}
谷歌的objective c教程。你会发现像这样的东西使用这个

在类a中创建数组并使其具有属性,然后在.m文件中合成它。然后推到下一个视图,然后使用导航堆栈中的拾取对象来访问数组。请参见此

 FirstView *obj=(FirstView *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-2];

 //obj.array is the array which you want to use.