how to fetch image from array and show it on table view - iphone

I am fetching image from server and save it on a NSMutableArray. The result of array like that
myarray={"roger_50.jpg",....};
Now i dont know how to access this image on table view.

Just have proper URL for image in array. And pass it to NSURL object as a link.
NSURL *imageURL = [NSURL URLWithString:[myarray objectAtIndex : yourindex]];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [[UIImage alloc] initWithData:data];
Have a nice coding.
Stay Hungry, Stay Foolish...

i hope the thing you are getting from array are only the names you can retrieve images from server in only two ways i) in nsdata ii)by url of the images on sever .By this way you cann't access the images.

Related

iPhone NSMutableArray loading background image from url

I have a NSMutableArray where it stores url to a image. And this NSMutableArray is called userPic. From my server it only prints out the url: not JSON or anything, only the url.
I can see in the output in Xcode that it shows the url, but how to I get this url in userPic to a background? Im trying to addSubView with the image for a background.
If something is unclear, sorry about that. Just let me know.
Please try to use this one.And i think your URL at index 0 of your array.
NSURL *imgURL = [NSURL URLWithString:[userPic objectAtIndex:0]]; // put your particular index where your image url in your array...
NSData *imgData = [[NSData alloc]initWithContentsOfURL:imgURL];
UIImage *img = [UIImage imageWithData: imgData];
[newView setBackgroundColor:[UIColor colorWithPatternImage:img]]

Getting image from gallery of Facebook and show it in iPhone

I want get image from public perfil of Facebook and show it in my iPhone. I'm using the Facebook Developer method "getPhoto" but I canĀ“t show any image?
Can someone help me?
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
As told Previously your problem to retrieve the object id. Here is the solution:-
To retrieve the images of your friend. Create the connection with the url
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#",accessTokenValue];
above url when hit returns an array of dictionary in which name of your friend and his id is written. Just Json parse that you will get the id of the person.
you need to use graph api for this purpose
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];

TTPhotoViewController get current center image?

Is there a way to get a current image to an object of UIImage? I have tried casting TTPhoto to UIImage, but it doesn't work.
I did this differently. My Photo source is generated using JSON data so I couldn't use the method above as the photo source is different every time. Instead I used the URLForVersion method on TTPhoto to download the image into a UIImage.
NSURL *imageURL = [NSURL URLWithString:[self.centerPhoto URLForVersion:TTPhotoVersionLarge]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
I figured it out. We can use TTPhotoViewController's instance variable centerImageIndex. This will give us the index of the current image.

How to get image URL out of NSArray?

So I have an NSDictionary with 4 objects in it. Each of these objects then has 2 properties, name and date
I can list out all the data by logging it.
You have an NSArray which contains several dictionaries. Firstly,get one dictionary out of the array like this,
NSDictionary *myDict=[myArray objectAtIndex:0];
assuming u have this array under the name myArray. You will get the first dictionary from the array which contains medium,thumbnails,title and another key called url. thumbnails is an array which holds a dict wid a key called url. Now if u want to fetch the outside url key tat is in the myArray just do like this,
NSString *myURL=[myDict valueForKey:#"url"];
This should fetch the url value..Hope this helps.... Happy coding...
NSData *myData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURL]];
UIImage *myImage = [[UIImage alloc] initWithData:myData;
Now you have ur image. Just create an imageView and set this image to it. To add it to a table, use contentView property like this,
[cell.contentView addSubView:myImageView];
Hope this helps.

How to download an image from the web and display it in an UIImageView?

How to download an image from the web and display it in an UIImageView? For example, I have an URL like:
http://sstatic.net/so/apple-touch-icon.png
Would I need to mess around with NSURLConnection and the like, or is there a simple method that takes an web URL and downloads the image data automatically?
You can use NSData's dataWithContentsOfURL: class method to download the image data from the server, then just pass that data to UIImage's imageWithData:class method.
Here's an example:
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://sstatic.net/so/apple-touch-icon.png"]];
UIImage *downloadedImage = [UIImage imageWithData:imageData];
myImageView.image = downloadedImage;