我想用尽可能少的代码创建一个整数数组,并将该数组传递给一个 Objective-C 方法。
我尝试了以下方法。 sequence
以数组形式开始并传递给 setLights:
但是当在方法中查看 sequence
时(通过断点)它不再数组。
*编辑:我不想使用 NSArray,因为整数的 NSArray 太冗长了:
使用 NSArray:
NSArray *sequence = [[NSArray alloc] initWithObjects: [NSNumber numberWithInt:0], [NSNumber numberWithInt:1], [NSNumber numberWithInt:2], [NSNumber numberWithInt:3], [NSNumber numberWithInt:4],[NSNumber numberWithInt:5],nil];
使用 C 数组:
int sequence[6] = {0,1,2,3,4,5};
我做错了什么?
- (IBAction)testLights:(id)sender {
int sequence[6] = {0,1,2,3,4,5};
//int *sequence[0][1][2][3][4][5]; //also tried this
[self setLights:sequence];
}
- (void)setLights:(int *)sequence {
UIImageView *light=[lgtArray objectAtIndex: sequence[0]];
light.alpha = 0;
[UIView animateWithDuration:0.3f
animations:^{
light.alpha = 1;
}completion:nil
];
}
最佳答案
使用此语法传递数组:
- (void)setLights:(int[] )sequence
关于objective-c - 将 C 数组传递给 Objective-C 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23420826/