2013-01-14 6 views
0

나는 코코아에 새로 온 사람과 나는 IKImageBrowserView을 가지고 있고 그것이 내가 여기에 이미지를로드하는 방법은 다음과 같습니다폴더에서 ikimagebrowser에 이미지를로드 하시겠습니까?

- (IBAction)loadImages:(id)sender 
{ 
NSMutableArray *urls = [[NSMutableArray alloc]init]; 
int i = 1; 
for (i=1; i<55; i++) { 
    NSString *photoNumber = [NSString stringWithFormat:@"%i", i]; 
    NSMutableString *urlString = [[NSMutableString alloc] initWithString:@"Australia"]; 
    [urlString appendString:photoNumber]; 
    NSURL* url = [[NSBundle mainBundle] URLForImageResource:urlString]; 
    [urls addObject:url]; 
} 
[self addImagesWithPaths:urls]; 
} 

    - (void)addAnImageWithPath:(NSString *)path 
{ 
    myImageObject *p; 

/* add a path to our temporary array */ 
p = [[myImageObject alloc] init]; 
[p setPath:path]; 
[_importedImages addObject:p]; 
} 

- (void)addImagesWithPath:(NSString *)path recursive:(BOOL)recursive 
{ 
NSInteger i, n; 
BOOL dir; 

[[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&dir]; 

if (dir) 
{ 
    NSArray *content = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; 

    n = [content count]; 

    // parse the directory content 
    for (i=0; i<n; i++) 
    { 
     if (recursive) 
      [self addImagesWithPath:[path stringByAppendingPathComponent:[content objectAtIndex:i]] recursive:YES]; 
     else 
      [self addAnImageWithPath:[path stringByAppendingPathComponent:[content objectAtIndex:i]]]; 
    } 
} 
else 
{ 
    [self addAnImageWithPath:path]; 
} 
} 

/* performed in an independant thread, parse all paths in "paths" and add these paths in our temporary array */ 
- (void)addImagesWithPaths:(NSArray *)urls 
{ 
    NSInteger i, n; 

n = [urls count]; 
for (i= 0; i < n; i++) 
{ 
    NSURL *url = [urls objectAtIndex:i]; 
    [self addImagesWithPath:[url path] recursive:NO]; 
} 

/* update the datasource in the main thread */ 
[self performSelectorOnMainThread:@selector(updateDatasource) withObject:nil waitUntilDone:YES]; 
} 

은 이제 내 이미지는 이름으로로드 - "호주"@. 이미지에 동일한 이름과 번호가 있어야하므로 불편합니다. xcode로 가져온 폴더의 이름이 다른 이미지를 어떻게로드합니까?

그래서 지금은 Australia1, Australia2, Australia3, Australia4 ... 등으로 이미지를로드하고 있습니다. 번들 폴더에서 이미지를로드하려면 어떻게해야합니까?

+0

. 코코아 및 이미지 키트는 OS X에서만 사용할 수 있습니다. –

+0

당신이하려는 일이나 그 대신에 어떤 일이 발생하는지 분명하지 않습니다. "내 이미지가 이름으로로드됩니다 - @"호주 ""라는 뜻입니까? "당신의 이미지는 같은 이름과 번호를 가져야합니다"라는 의미는 무엇입니까? "폴더와 다른 이름으로 이미지로드"는 여기에서하는 것과 어떻게 다른가요? –

+0

나는 그것을 코코아로 태그했다고 생각하지 않는다 ... 음, 어쨌든, 순간에 내 이미지가 루프에 이름으로로드되므로 "Australia1, Australia2, Australia3 ..."라는 이미지가있다. 번들 폴더에서 이미지를 어떻게로드합니까? – Rokas

답변

1

데이터 소스는 IKImageBrowserItem 프로토콜을 준수하는 이미지 브라우저보기로 항목을 반환해야합니다. myImageObject 클래스는 시작하기에 좋은 장소입니다. 해당 프로토콜에서

는 세 가지 방법이 필요합니다 :

처음에는 모든 myImageObject에 이미 제공하고있는 경로를 사용하고 싶습니다. 이것을 식별자 문자열과 이미지 표현 모두로 사용할 수 있습니다.

이 앱에서 수행중인 작업에 따라 나중에 메모리 및/또는 속도상의 이유로 각 이미지를 직접로드하는 것이 유리할 수 있습니다. 프로파일 링 한 후에 그 결론에 도달하면 NSImage 또는 CGImage로 이미지를로드하고 표현 유형을 적절히 변경 한 다음 이미지를 표현으로 반환 할 수 있습니다.

데이터 원본으로, 당신은 당신의 _importedImages 배열에 the number of items를 돌아갑니다, 그리고 the item at an index에 대해 물었을 때, objectAtIndex:를 통해 해당 항목을 반환합니다.

상세 정보 : 당신은 아이폰 OS로이 태그 이유를 모르겠어요

+0

배열에 이미 NSImages 그룹이 있습니다. 데이터 소스 프로토콜 요구 사항에는 무엇을 사용해야합니까? 감사합니다 –

+0

말을 잊어 버렸습니다 -이 이미지는 그물에서 직접 변경 가능한 배열로 다운로드됩니다. –

+0

@DavidDelMonte : 프로토콜을 준수하는 클래스를 만들고 각 이미지를 인스턴스에 래핑합니다. –