2
我在文檔目錄上有不同的文件夾,並在每個文件夾上都有圖像。現在我想顯示來自不同文件夾的一個圖像。我已經嘗試過,但該方案是在線路上的衝突。UITableView Cell上的圖像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//I dont know what put here for display from sqlite
NSUInteger row = [indexPath row];
cell.textLabel.text = [array1 objectAtIndex:row];
//cell.detailTextLabel.text = [array2 objectAtIndex:row];
NSString *b = [array2 objectAtIndex:row];
NSLog(@"b=%@",b);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSError *error = nil;
NSArray *imageFileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",b]] error:&error];
NSLog(@"file=%@",imageFileNames);
NSMutableArray *images = [[NSMutableArray alloc ] init];
for (int i = 0; i < [imageFileNames count]; i++)
{
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/%d.png",b, i]];
UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
[images addObject:img];
NSLog(@"%@",getImagePath);
}
NSLog(@"images=%@",images);
cell.imageView.image=[imageFileNames objectAtIndex:0];
//NSLog(@"row=%u",row);
return cell;
}
哪裏喲你得到錯誤? –
cell.imageView.image = [imageFileNames objectAtIndex:0];當你只使用一個圖像時,爲什麼要運行一個循環來爲圖像填充陣列,並且在每個單元格上也填充圖像?其次,你能告訴我們你如何確定從每個文件夾顯示哪個圖像? –
那麼,我該怎麼做。 – Nasir