156 lines
4.5 KiB
Objective-C
156 lines
4.5 KiB
Objective-C
//
|
|
// FESVenuesTableViewController.m
|
|
// FestivalHelper
|
|
//
|
|
// Created by Hamo Hapic on 04/09/14.
|
|
// Copyright (c) 2014 Senad Uka. All rights reserved.
|
|
//
|
|
|
|
#import "FESVenuesTableViewController.h"
|
|
#import "FESVenueEntry.h"
|
|
#import "FESDataProvider.h"
|
|
#import "FESVenueEntryCell.h"
|
|
|
|
@interface FESVenuesTableViewController ()
|
|
|
|
@end
|
|
|
|
@implementation FESVenuesTableViewController
|
|
|
|
@synthesize venuesArray;
|
|
|
|
- (id)initWithStyle:(UITableViewStyle)style
|
|
{
|
|
self = [super initWithStyle:style];
|
|
if (self) {
|
|
// Custom initialization
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
[FESDataProvider getDataFromServerForUrl:VENUES_URL andProcessThemWith:^(NSData *data) {
|
|
[self setupVenuesFromJSONArray:data];
|
|
[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
|
|
}];
|
|
|
|
// Uncomment the following line to preserve selection between presentations.
|
|
// self.clearsSelectionOnViewWillAppear = NO;
|
|
|
|
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
|
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning
|
|
{
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
|
{
|
|
// Return the number of sections.
|
|
return 1;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
|
{
|
|
// Return the number of rows in the section.
|
|
return [venuesArray count];
|
|
}
|
|
|
|
|
|
-(void)setupVenuesFromJSONArray:(NSData*)dataFromServerArray{
|
|
NSError *error;
|
|
self.venuesArray = [[NSMutableArray alloc] init];
|
|
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 {
|
|
self.venuesArray = [[NSMutableArray alloc] init];
|
|
for(NSDictionary *venueData in arrayFromServer)
|
|
{
|
|
FESVenueEntry *entry = [[FESVenueEntry alloc] initWithJSONData:venueData];
|
|
[self.venuesArray addObject:entry];
|
|
}
|
|
NSLog(@"success!");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
UITableViewCell *retrievedCell = [tableView dequeueReusableCellWithIdentifier:@"venueEntryCell" forIndexPath:indexPath];
|
|
FESVenueEntryCell *cell = (FESVenueEntryCell *)retrievedCell;
|
|
|
|
FESVenueEntry *venueEntry = [venuesArray objectAtIndex:indexPath.row];
|
|
|
|
cell.venueName.text = venueEntry.venueName;
|
|
cell.venueAddress.text = venueEntry.venueAddress;
|
|
cell.venueCapacity.text = venueEntry.venueCapacity;
|
|
|
|
|
|
return cell;
|
|
}
|
|
|
|
|
|
/*
|
|
// Override to support conditional editing of the table view.
|
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
// Return NO if you do not want the specified item to be editable.
|
|
return YES;
|
|
}
|
|
*/
|
|
|
|
/*
|
|
// Override to support editing the table view.
|
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
// Delete the row from the data source
|
|
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
|
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
}
|
|
}
|
|
*/
|
|
|
|
/*
|
|
// Override to support rearranging the table view.
|
|
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
|
|
{
|
|
}
|
|
*/
|
|
|
|
/*
|
|
// Override to support conditional rearranging of the table view.
|
|
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
// Return NO if you do not want the item to be re-orderable.
|
|
return YES;
|
|
}
|
|
*/
|
|
|
|
/*
|
|
#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
|