NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:post.imageURL]];
UIImage *img = [[UIImage alloc] initWithData:imgData];
I have this code and imgData always gets nil. I checked post.imageURL and it returns a string which in a url format. I also replaced the string with a constant string(URL format) that I hardcoded but imgData still got null. This code runs on the background. Do you guys see any problem?
Your code looks good, are you sure your URL is valid ?
If post.imageURL is not valid, thus URLWithString: will be null and also your data.
I have tried with "http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" to be sure, and it worked, so I guess the problem come from your URL.
Split your code :
NSURL *url = [NSURL URLWithString:#"http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:imgData];
And check the value of each of the variable.
Related
NSURL *url = [NSURL URLWithString:[self.imageArray objectAtIndex:indexPath.row]];
NSLog(#"My URL : %#",url);
NSData *data = [NSData dataWithContentsOfURL:url];
NSLog(#"New Data : %#",data);
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
cell.imageView.image = tmpImage;
i think i got your problem, check this like my upload image in your project.
i also make a gif about how to add this setting in your project , just follow the step in my gif.
What syntax could I use to make this work?
UIImage with NSURL
banner.image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.website.com/file.file"+placemark.administrativeArea+#".png"]]];
Thanks!
Use This way:
banner.image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.website.com/file.file%#.png",placemark.administrativeArea]]]];
Don't use so much statement in one line.
IT has several problem like Difficult to understand and Hard to find error.
I suggest this way:
NSString *imgStr = [NSString stringWithFormat:#"http://www.website.com/file.file%#.png",placemark.administrativeArea];
NSURL *imgURL = [NSURL URLWithString:imgStr];
NSData *imgData = [NSData dataWithContentsOfURL:imgURL];
UIImage *img = [[UIImage alloc] initWithData:imgData];
banner.image = img;
But it depend on u.
Good day..
following problem:
I created a NSXMLParser subclass to get Xbox Live profile data, the class works fine but i have a problem with displaying an image.
NSLog(#"%#", [[xbl.games objectAtIndex: i] objectForKey: #"Image64Url"]);
output:
http://tiles.xbox.com/tiles/+4/R1/1Wdsb2JhbC9ECgUAGwEfV1oiL2ljb24vMC84MDAwAAAAAAAAAPpahOQ=.jpg
displaying the image:
NSURL *url = [NSURL URLWithString:[[xbl.games objectAtIndex: i] objectForKey: #"Image64Url"]];
NSData *data = [NSData dataWithContentsOfURL:url];
gamerPicView.image = [[UIImage alloc] initWithData:data];
Does not work, but if i run:
NSURL *url = [NSURL URLWithString:#"http://tiles.xbox.com/tiles/+4/R1/1Wdsb2JhbC9ECgUAGwEfV1oiL2ljb24vMC84MDAwAAAAAAAAAPpahOQ=.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
gamerPicView.image = [[UIImage alloc] initWithData:data];
Its working, im really confused whats my mistake?
Thanks for help and greetings from switzerland.
I would print what 'url' is after your first (unsuccessful) attempt at displaying the image and see if it is the same URL or not as the code that works, since this seems like the only place something could be wrong.
Edit: And if you still can't figure out the problem, post the NSLog output for 'url' in both cases.
I'm using the following code to fetch some images, that are going into a tableview. But it takes ages (5-6 seconds) to get the 30 images in.
Is there a smarter/faster way to do this?
NSString *imageUrl = ......;
NSString *urlStr =
[imageUrl UrlstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[NSString alloc] initWithFormat:#"http://xxx.dk/xml.aspx%#", urlStr];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
return img;
[..... release];
Here profileimg is an get from Api ,String name
NSString *profileimg=[Check objectForKey:#"IMAGE"];
imageview.image=[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profileimg]]];
I'd rather download every new image in array of images when a cell appears on the screen and just display already saved image if a cell appears on the screen for the second time (i.e. image for this cell has been already downloaded).
use asynchronize loading of image.
check out this sample code : http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
Am having some difficulty getting an Image from a url, and then displaying it in an image well in the interface.
This is the code I'm currently using, it doesn't work and compiles with no errors:
NSURL *url = [NSURL URLWithString:#"http://www.nataliedee.com/061105/hey-whale.jpg"];
NSString *newIMAGE = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[imageView setImage:[NSImage imageNamed:newIMAGE]];
Any ideas as to what is wrong here?
You are passing in image data as a string to a method that is trying to use that string as the name of the image, which of course doesn't exist.
What you need to do is create an NSData object from your URL dataWithContentsOfURL:, once you have the NSData object use this to create the UIImage via imageWithData:.