2012-10-28 6 views
0

에로드하십시오. 내 프로젝트에서 이미지를 내 전화기의 문서 폴더에 저장하고 별도의 테이블 뷰에로드하고 있습니다. 나는 약간의 성공을 거두고 있으며, 마지막으로 찍은 이미지는 테이블에로드되지만 마지막 행 대신 모든 행에로드됩니다. 여기plist에 저장된 모든 이미지를 테이블 뷰

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"List"; 
ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
//Load PLIST 
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [path objectAtIndex:0]; 
NSString *plistPath = [NSString stringWithFormat:@"%@/images.plist", documentsDirectory]; 
//Load PLIST into mutable array 
NSMutableArray *imageArray = [NSMutableArray arrayWithContentsOfFile:plistPath]; 

for (NSDictionary *dict in imageArray) { 
//Do whatever you want here, to load an image for example 
    NSString *imageFilePath = [NSHomeDirectory() stringByAppendingPathComponent:[dict objectForKey:@"Original Image"]]; 
    UIImage *image = [UIImage imageWithContentsOfFile:imageFilePath]; 
    [cell.imageofItem setImage:image]; 
} 
} 

을 무슨 일이 일어나고 있는지의 예입니다 : 여기 내가있는 tableview에서 이미지를로드하는 데 사용되는 코드는 내가, 하나는 "10282012_13113138_image.jpg"라고이 사진을 찍어 말해 다른 호출된다 "10282012_13113468_image.jpg". 그런 다음 셀에 이미지를로드하고 마지막 사진을 두 셀에로드합니다.

도움이 될 것입니다.

시도

+2

나는 어떻게 UIImage 이래로 일하고 있는지 잘 모르겠다. '이미지는 for 루프에서 선언되지만 for 루프의 컨텍스트 외부에서 사용되고 있습니다. – bobnoble

+0

@bobnoble 죄송합니다. 잘못 입력했습니다. 이제 –

+0

을 수정했습니다. 어디에서 초기화되었거나 - (void) loadImages에 할당 되었습니까? – yeesterbunny

답변

1

대신

for (NSDictionary *dict in imageArray) { 
    NSString *imageFilePath = [NSHomeDirectory() stringByAppendingPathComponent:[dict objectForKey:@"Original Image"]]; 
    UIImage *image = [UIImage imageWithContentsOfFile:imageFilePath]; 
    [cell.imageofItem setImage:image]; 

}

NSDictionary *dict = [imageArray objectAtIndex:indexPath.row]; 
    NSString *imageFilePath = [NSHomeDirectory() stringByAppendingPathComponent:[dict objectForKey:@"Original Image"]]; 
    UIImage *image = [UIImage imageWithContentsOfFile:imageFilePath]; 
    [cell.imageofItem setImage:image]; 

문제는 각 indexPath.row를 들어, 지속적으로 덮어 쓰기, 배열의 마지막 요소까지 반복 있다고했다 셀 이미지를 마지막 이미지까지 가져옵니다. 그럼 다음 indexPath.row, 당신은 똑같은 일을하고, 배열의 마지막 이미지로 설정하고, 등등 ....

+0

정확히 내가 뭘 찾고 있었는지, 고마워! –

관련 문제