Sunday, April 26, 2015

TableViewController with data from Library

//
//  MyTableViewController.h
//  MyTableViewApplication
//
//  Created by Krishnan Sriram Rama on 4/26/15.
//  Copyright (c) 2015 Krishnan Sriram Rama. All rights reserved.
//

#import

@interface MyTableViewController : UITableViewController


@end


//
//  MyTableViewController.m
//  MyTableViewApplication
//
//  Created by Krishnan Sriram Rama on 4/26/15.
//  Copyright (c) 2015 Krishnan Sriram Rama. All rights reserved.
//

#import "MyTableViewController.h"
#import "MyTableViewCellData.h"
#import "MyTableViewCellDataCollection.h"
#import "MyTableViewDetailedWebViewController.h"

@interface MyTableViewController ()
@property (nonatomic, strong) NSDictionary *tableData;
@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTableData:[[MyTableViewCellDataCollection sharedManager] tableData]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[self tableData] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    NSString *currentIndex = [NSString stringWithFormat:@"%ld", ([indexPath row] + 1)];
    MyTableViewCellData *cellData = [[self tableData] objectForKey:currentIndex];

    [[cell textLabel] setText:[cellData cellData]];
    [[cell detailTextLabel] setText:[cellData subCellData]];
    
    return cell;
}

@end

No comments: