菜鸟问题在这里。
如果我有一个带有数组 float itemsPosition[20][20] 的 A 类,并且我有另一个 B 类来访问它,我该怎么做?
我通常这样做是为了分配 A 类并访问其他对象,但在这种情况下,我无法在 A 类中合成 float 组。
有什么想法吗?
最佳答案
您可以@synthesize
一个NSValue
来保存指向数组的指针。
@interface SomeObject : NSObject
@property (strong, nonatomic) NSValue *itemsPosition;
@end
@implementation SomeObject
@synthesize itemsPosition;
...
static float anArray[20][20];
...
- (void) someMethod
{
... add items to the array
[self setItemsPosition:[NSValue valueWithPointer:anArray]];
}
@end
@implementation SomeOtherObject
...
- (void) someOtherMethod
{
SomeObject *obj = [[SomeObject alloc] init];
...
float (*ary2)[20] = (float(*)[20])[obj.itemsPosition pointerValue];
...
}
关于objective-c - 从另一个类调用 float 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667318/