Reputation: 6660
I am trying to add an image to each cell of my tableview :
- (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];
}
NSString *ligneTableau = [NSString stringWithFormat:@"%@", [[tableau objectAtIndex:indexPath.row] label]];
cell.textLabel.text=ligneTableau; // Configure the cell.
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"images/sections/%@.png", [[tableau objectAtIndex:indexPath.row] key]]];
return cell;
}
When i NSLog() the string of imageNamed, i get the good url ( "images/sections/name.png"). All my images are in the subfolder "images" of my project as "images/sections/name.png".
But my images don't appear on my rows but if i replace images/sections/%@.png by a image file name in the root of my project, it works.
Why can i not read the images of my subfolder?
Thank you (i am a beginner)
Upvotes: 0
Views: 580
Reputation: 6147
That's about how Xcode works and how bundles work. The path your image is in your Xcode project is not the same path as the image is in the generated app bundle. So check your .app bundle and take the path from there. By default if you add an image to your Xcode project it will be copied to the root of your .app bundle. If you want an entire folder to be as in your app bundle as a folder. You have to add it as a folder (not as a group) to your Xcode project.
Upvotes: 2