我新的可可和我有一個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的文件夾加載具有不同名稱的圖像?
所以目前我按照名稱澳大利亞1,澳大利亞2,澳大利亞3,澳大利亞4等等加載圖片。 如何從包文件夾加載圖像?
我不知道爲什麼你這個標記爲的iOS。 Cocoa和Image Kit只在OS X上可用。 –
目前還不清楚你正在嘗試做什麼或者發生了什麼。你的意思是「我的圖片是按名稱加載的 - @」澳大利亞「」? 「你的照片需要有相同的名字和數字」是什麼意思? 「從文件夾加載具有不同名稱的圖像」與您在此做的有何不同? –
我不認爲我把它標記爲可可...好吧,無論如何,此刻我的圖像被加載成一個循環的名字,所以我得到了名爲「澳大利亞1,澳大利亞2,澳大利亞3 ...」等圖像。如何從包文件夾加載圖像? – Rokas