iphone,在类之间传递数组?
答
你想要的是简单的对象成员来设置。要实现这一目标的最好方法是使用性质: http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html#//apple_ref/doc/uid/TP40007594
在波黑:
@property(nonatomic,retain) NSArray * theArray_B;
在BM:
@synthesize theArray_B;
在上午
:
myB_Instance.theArray_B = theArrayToPass;
在该示例A和B共享一个指向内存中同一个Array-Object的指针。此外B拥有这个数组(A也是),因为它有一个保留。
答
事情是这样的:
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/
答
使用此。
在类a中创建数组并将其合并到.m文件中。然后推入下一个视图,然后使用导航堆栈中的拾取对象来访问数组。
FirstView *obj=(FirstView *)[self.navigationController.viewControllers objectAtIndex: [self.navigationController.viewControllers count]-2];
//obj.array is the array which you want to use.