Right now, I’ve just some code which fetches the picture from the URL directly.
ViewController.h
(...)
@property (retain, nonatomic) IBOutlet UIImageView *imageView;
(...)
ViewController.m:
#import Header.h
(...)
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *imageURL = [NSURL URLWithString:@"http://www.visitingdc.com/images/eiffel-tower-picture.jpg"];
NSData *myImageData = [NSData dataWithContentsOfURL:imageURL];
imageView.image = [UIImage imageWithData:myImageData];
}
My goal is to view a picture in a imageView which link is stored in a database. The JSON will send the data from the database as a string:
[
{
"image":"http://www.visitingdc.com/images/eiffel-tower-picture.jpg"
}
]
which will be stored in the variable *image in Header.
Header.h
@interface Header : NSObject {
NSString *image;
}
@property (nonatomic, copy) NSString *image;
- (id)initWithDictionary:(NSDictionary *)dictionary;
+ (NSArray *)findAllRemote;
@end
What do I have to write in the NSURL-code in ViewController.m so it fetches the data from the variable instead of a URL-String?
You can store json response in NSSTring, like
and then use –