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