Convert Object to String iPhone SDK
I have got something strange: This Code does NOT Work: cell.imvstatu开发者_如何学Gos.image = [UIImage imageNamed:[[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"] ];
This code works:
cell.imvstatus.image = [UIImage imageNamed:@"ROR.png" ];
And in the object there is the value "ROR.png"
Whats the problem at the above one?
How can I find out a solution? Do i have to cast it to a string ?
Try casting it as a string like this:
NScell.imvstatus.image = [UIImage imageNamed: (NSString *) [[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"] ];
The key is the (NSString *)
.
The only thing we can assume is [[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"]
doesn't contain ROR.png.
Try doing NSLog debugging by adding the following lines of code (and looking at the console output, in Xcode under the menu Run > Console):
NSLog(@"tutorials: %@", tutorials);
NSLog(@"row index: %d", indexPath.row);
NSLog(@"row content: %@", [tutorials objectAtIndex:indexPath.row]);
NSLog(@"image: %@",
[[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"]);
There probably is something unexpected there.
Ok I have found it out:
image = "ROR.png\n"; contains a \n
I have to replace it.BUT:
OK now The Output is: 2009-11-09 09:17:31.606 remotegui[1667:207] image: ROR.png But when i write out the length of the string the string is 8 chars long:
2009-11-09 09:17:31.606 remotegui[1667:207] bildlength: 8
精彩评论