I created a plist that contains an NSDictionary structure. The key is a label (which I use to populate tableview cell.text) and the value is a file name that I want to use to ‘dynamically’ populate cell.image. The exact png filenames are loaded into the project.
To make things easier (so I thought), I load the plist into an NSDictionary, then pull that apart into two arrays (using allKeys and allValues).
In attempting to set a cell image, I dont understand why this works:
cell.image = [UIImage imageNamed:@"bad.png"];
and this does not (in simulator – I get an app crash and barfing in debugger):
cell.image = [UIImage imageNamed:[rowImageList objectAtIndex:indexPath.row]];
I can put this next line right before the second piece of code and it works just fine, so it appears that I am getting an NSString from objectAtIndex:
NSLog(@"Image name: %@", [rowImageList objectAtIndex:indexPath.row]);
I have also tried creating a temp NSString and assigning [rowImageList objectAtIndex:] to it, then using that NSString to supply imageNamed:.
Here is some info from debugger:
-[NSCFArray length]: unrecognized selector sent to instance 0x262d910
Terminating app due to uncaught
exception
‘NSInvalidArgumentException’, reason:
‘*** -[NSCFArray length]: unrecognized
selector sent to instance 0x262d910’
Let me know if you need more info/code.
Edit: Here’s how I populate rowImageList:
NSArray *myRowImages = [[NSArray alloc] init];
myRowImages = [searchFilterList allValues];
self.rowImageList = [myRowImages copy];
[myRowImages release];
//where searchFilterList is an NSDictionary that I loaded from a plist
Here’s a screenshot of my plist:
[IMG][
]1
[/IMG]
Edit: revised rowImageList population:
NSMutableArray *myRowImages = [[NSMutableArray alloc] init];
NSEnumerator *enumerator = [searchFilterList objectEnumerator];
id object;
while ((object = [enumerator nextObject])) {
[myRowImages addObject:[object objectAtIndex:0]];
}
self.rowImageList = myRowImages; //edit: added self. prefix
[myRowImages release];
I would double-check the output from NSLog() and make sure it’s not an array that contains an NSString. That’s what the error is telling you; you’re passing an NSArray where an NSString is expected.