Skip to content

Instantly share code, notes, and snippets.

@jonpacker
Forked from anonymous/gist:1399819
Created November 28, 2011 09:57
Show Gist options
  • Save jonpacker/1399824 to your computer and use it in GitHub Desktop.
Save jonpacker/1399824 to your computer and use it in GitHub Desktop.
//
// SecondViewController.m
// c8h10n4o2
//
// Created by Håkon Sørensen on 10.11.11.
// Copyright (c) 2011 SorensenWeb. All rights reserved.
//
#import "SecondViewController.h"
#import "ASIHTTPRequest.h"
#import "JSONKit.h"
#import "UIImageView+WebCache.h"
@implementation SecondViewController
@synthesize imageView = _imageView;
@synthesize dataItem = _dataItem;
- (void) loadData {
NSString* dataUrl = @"http://192.168.1.32/kaffebaren/dagens/dagens.json";
__block ASIHTTPRequest* request = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:dataUrl]];
[request setCompletionBlock:^{
id result = [request.responseData objectFromJSONData];
NSDictionary* data = [request.responseData objectFromJSONData];
NSArray* posts = [data objectForKey:@"posts"];
NSDictionary* imageData = [posts objectAtIndex:0];
NSString* imageURL = [imageData objectForKey:@"image"];
[_imageView setImageWithURL:[NSURL URLWithString:[result objectForKey:@"image"]]];
}];
[request setFailedBlock:^{
// Would normally handle errors here
}];
[request startAsynchronous];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadData];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment