Q:

Using imageNamed fails on device, but works in simulator

Here is my code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:nil];
    NSMutableArray *finalArray = [(NSArray*)filePathsArray mutableCopy];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *files = [fm contentsOfDirectoryAtPath:documentsDirectory error:nil];
    NSString *fileFirst = [files objectAtIndex:0];
    NSString *fullPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileFirst];
    /* NSUInteger index = [finalArray indexOfObject:@".DS_Store"];
    [finalArray removeObjectAtIndex: index]; */
    //NSLog(@"files array %@", finalArray);
    NSString *title = [[[finalArray objectAtIndex:indexPath.row] lastPathComponent]stringByDeletingPathExtension];
    NSString *image = [[finalArray objectAtIndex:indexPath.row] lastPathComponent];
    NSString *newimage = [[image pathExtension]stringByAppendingPathExtension:@"png"];
    //NSLog(@"%@",newimage);

    if (![UIImage imageNamed:newimage]) {
        newimage = @"notFound.png";
    }

    NSDictionary *fileAttribs = [[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:nil];
    ////NSLog(@"Here: %@",fileAttribs);
    //long long fileSize = [fileAttribs fileSize];

    NSDate *result = [fileAttribs valueForKey:NSFileCreationDate]; //or NSFileModificationDate
    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]  autorelease];
    [dateFormatter setDateStyle:NSDateFormatterLongStyle];
    NSString *dateString = [dateFormatter stringFromDate:result];   
    [dateFormatter setDateStyle:NSDateFormatterNoStyle];

    cell.textLabel.text = title;
    cell.imageView.image = [UIImage imageNamed:newimage];
    //cell.detailTextLabel.text = [NSString stringWithFormat:@"File extenstion: %@",[[image pathExtension]uppercaseString]];
    cell.detailTextLabel.text = dateString;
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;
}

As you can see above, I get the extension of a file in the users Documents folder and find the image with that extension.  This works - I get the right image (PDF.png for example) when I NSLog the string  However, if the image cannot be found, I want the newimage variable to be notFound.png.
This works on the simulator, but not when I test on a device.  On a device, the all of the cell.imageView.image come up as notFound.png, even if the cell NSLogs PDF.png (for example).  Anyone have any ideas on what the problem is?  Thanks.

A:

The file system used by Mac OS X (and thus your simulator) is generally configured not to be case sensitive (it preserves case when you create filename, but doesn't matter if you retrieve with the wrong capitalization). The device is case sensitive, though. 
If you see difference in finding files via imageNamed (or anything that's reading a file from the local file system) between the platforms, check your capitalization.

If you're still not finding it, I'd then suggest making sure the file shows up in the target's "Build Phases" and check the "Copy Bundle Resources" section with the right capitalization for both the base filename and the extension. I'd also make sure you do a "Product" - "Clean" and rebuild the app, as sometimes Xcode gets confused about what files have been copied over. I also assume you've quit and restarted Xcode, because when I see that rare, completely unexplainable behavior, restarting Xcode (or sometimes even my machine) will fix it.

