我想从A类传递一个数组到B类,但A调用B。
答案 0 :(得分:0)
您想要的是要设置的简单对象成员。实现这一目标的最佳方法是使用属性: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html#//apple_ref/doc/uid/TP40007594
在B.h:
@property(nonatomic,retain) NSArray * theArray_B;
在B.m:
@synthesize theArray_B;
在A.m:
myB_Instance.theArray_B = theArrayToPass;
在该示例中,A和B共享指向内存中相同Array-Object的指针。此外B拥有这个数组(A也有),因为它有一个保留。
答案 1 :(得分:0)
这样的事情:
A类包含:
- (void)someMethodInClassA {
NSArray *arrayData = // ... stuff
ClassB *classB = // ... stuff
[classB aMethod:arrayData];
}
B类包含:
- (void)aMethod:(NSArray *)array {
// do something with the array
}
谷歌的目标c教程。你会发现像http://howtomakeiphoneapps.com/objective-c-tutorial/
这样的东西答案 2 :(得分:0)
使用它。
在类a中创建数组并使其成为属性并在.m文件中合成它。然后推送到下一个视图,然后使用导航堆栈中的pick对象访问array.see this。
FirstView *obj=(FirstView *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-2];
//obj.array is the array which you want to use.