How to load image from NSMutableArray
I want to load the image URL from my NSMutableArray. Here is my Code:
id path = (NSString *)[[stories objectAtIndex: storyIndex] objectForKey: @"icon"];
NSURL *url 开发者_JAVA技巧= [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data cache:NO];
If I use: id path = @"http://www.xzy.de/icon.png"; it´s all right, but not if I want to extract the imageURL from my Array
Anyone who can help me? Thanks!
I don't get why you declare path
as anonymous id
type. Define it as NSString. Shouldn't be any problems.
Okay, here's the solution to the problem:
path = [path stringByReplacingOccurrencesOfString:@" " withString:@""];
path = [path stringByReplacingOccurrencesOfString:@"\n" withString:@""];
// that's a tab in the next line's string
path = [path stringByReplacingOccurrencesOfString:@" " withString:@""];
精彩评论