//
//  RootViewController.m
//  Card
//
//  Created by LuYang on 16/2/23.
//  Copyright 漏 2016骞?LuYang. All rights reserved.
//

#import "RootViewController.h"
static NSString * const reuseCellIdentifier = @"RootCellID";
@interface RootViewController ()
@property (nonatomic,strong)NSArray *cellTitleArray;
@property (nonatomic,strong)NSArray *classNameArray;
@end

@implementation RootViewController
-(void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"鍗$墖鍔ㄧ敾";
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"杩斿洖" style:UIBarButtonItemStyleDone target:nil action:nil];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseCellIdentifier];
}

#pragma mark -- TableView Delegate DataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.cellTitleArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseCellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseCellIdentifier];
    }
    cell.textLabel.text = self.cellTitleArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Class pushClass = NSClassFromString(self.classNameArray[indexPath.row]);
    if ([pushClass isSubclassOfClass:[UIViewController class]]) {
        UIViewController *pushViewController = [[pushClass alloc] init];
        pushViewController.title = self.cellTitleArray[indexPath.row];
        [self.navigationController pushViewController:pushViewController animated:YES];
    }
}

#pragma mark -- Lazy Loading
-(NSArray *)cellTitleArray
{
    if (!_cellTitleArray) {
        _cellTitleArray = @[@"鍗$墖灞傚彔鍔ㄧ敾",@"浠縤n鍔ㄦ€佸疄鐜?];
    }
    return _cellTitleArray;
}

-(NSArray *)classNameArray
{
    if (!_classNameArray) {
        _classNameArray = @[@"CardCollectionViewController",@"InViewController"];
    }
    return _classNameArray;
}
@end
// 鐗堟潈灞炰簬鍘熶綔鑰?// http://code4app.com (cn) http://code4app.net (en)
// 鍙戝竷浠g爜浜庢渶涓撲笟鐨勬簮鐮佸垎浜綉绔? Code4App.com