Files
old-festivalhelper/FestivalHelper/about/FESAboutViewController.m
2014-09-07 07:18:07 +02:00

92 lines
2.2 KiB
Objective-C

//
// FESAboutViewController.m
// FestivalHelper
//
// Created by Hamo Hapic on 07/09/14.
// Copyright (c) 2014 Senad Uka. All rights reserved.
//
#import "FESAboutViewController.h"
#import "FESDataProvider.h"
#import "FESAboutEntry.h"
@interface FESAboutViewController ()
@end
@implementation FESAboutViewController
@synthesize aboutEntry;
@synthesize aboutDescription;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[FESDataProvider getDataFromServerForUrl:ABOUT_URL andProcessThemWith:^(NSData *data) {
[self setupAboutFromJSONArray:data];
[self performSelectorOnMainThread:@selector(setupAboutFields) withObject:nil waitUntilDone:NO];
}];
}
-(void)setupAboutFromJSONArray:(NSData*)dataFromServerArray{
NSError *error;
NSArray *arrayFromServer = [NSJSONSerialization JSONObjectWithData:dataFromServerArray options:0 error:&error];
if(error){
NSLog(@"error parsing the json data from server with error description - %@", [error localizedDescription]);
}
else {
for(NSDictionary *aboutData in arrayFromServer)
{
FESAboutEntry *entry = [[FESAboutEntry alloc] initWithJSONData:aboutData];
self.aboutEntry = entry;
break;
}
NSLog(@"success!");
}
}
-(void)setupAboutFields {
if(aboutEntry != nil) {
self.navigationItem.title = aboutEntry.aboutFestivalName;
self.aboutDescription.text = aboutEntry.aboutDescription;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end