-1

对于下面的代码示例,通常我会使用[self fall];* 处的代码来代替,但我也需要将 的值i发送到fall方法。我该怎么做呢?

- (void)main {
    for (int i=0; i <= 100; i++) {
        [image[i] fall]; *
    }
}

- (void)fall {
    // manipulate image[i]; separately from the for loop
}

编辑:我会接受最旧的答案,因为一切都是正确的。谢谢!

4

2 回答 2

3

也许你的意思是:

- (void)main {
    for (int i=0; i <= 100; i++) {
        [image[i] fall:i];
    }
}

- (void)fall:(int)i {
    // manipulate image[i]; separately from the for loop
}

或者,也许你的意思是:

- (void)main {
    for (int i=0; i <= 100; i++) {
        [self fall:image[i]];
    }
}

- (void)fall:(NSImage *)image {
    // manipulate image[i]; separately from the for loop
}

如果不是,您需要澄清您的问题。

于 2012-06-28T15:47:15.240 回答
3

你需要做 -

 - (void)fall:(int)i {
     // manipulate image[i]; separately from the for loop
}

并打电话给 -

- (void)main {
for (int i=0; i <= 100; i++) {
    [image fall:i];
}

}

编辑 -

如果你想通过索引 -

 - (void)fall:(int)i {
     // manipulate image[i]; separately from the for loop
}

并打电话给 -

- (void)main {
for (int i=0; i <= 100; i++) {
    [self fall:i]; // Now from here you can either pass index
}

}

如果你想传递一些图像 -

 - (void)fall:(UIImage)i {
     // manipulate image[i]; separately from the for loop
}

并打电话给 -

- (void)main {
for (int i=0; i <= 100; i++) {
    [self fall:imageI]; // Now from here you need to pass image, if that image is stored in array, then fetch from array. Or you need to manipulate in the way in which you are storing.
}

}

于 2012-06-28T15:47:35.720 回答