2012-06-28 3 views
-1

아래 코드 예제에서는 대개 *에서 코드 대신 [self fall];을 사용하지만 값을 fall 메서드로 보내야합니다. 어떻게해야합니까?특정 값을 사용하는 메서드 호출

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

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

편집 : 나는 모든 것이 정확하므로 가장 오래된 대답을 수락합니다. 감사! 어쩌면 당신 말은,

- (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 
} 

을 또는 :

답변

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. 
} 

}

+0

이 방법을 사용하면 경고 메시지가 나타납니다. "UIImageView '가'fall : '에 응답하지 않을 수 있으며 루프가 실행될 때 앱이 멈 춥니 다. 어떤 아이디어? –

+1

예, 가능합니다. 메서드는 뷰 컨트롤러이므로 이미지 객체로 호출하면 확실히 실패합니다. 이전에는 이미지가 컨트롤러 이름이라고 생각합니다. 편집 된 게시물을 확인하십시오. – rishi

3

은 아마 당신은 의미

- (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 
} 

그렇지 않으면, 당신은 당신의 질문을 명확히 할 필요가있다.

+0

"UIImageView '가'fall : '에 응답하지 않을 수 있으며 루프가 실행될 때 앱이 정지됩니다. 어떤 아이디어? –

관련 문제