40.小项目:团购 C部分

------------- ViewController.m -------------

#import "CZViewController.h"

#import "CZTg.h"

#import "CZTgCell.h"

#import "CZHeaderView.h"

#import "CZTgFooterView.h"


@interface CZViewController () <UITableViewDataSource, CZTgFooterViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSArray *tgs;

@end


@implementation CZViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.tableView.rowHeight = 60;

    CZTgFooterView *view = [CZTgFooterView footerView];

    view.delegate = self;

    self.tableView.tableFooterView = view;

    CZHeaderView *headerView = [CZHeaderView headerView];

    self.tableView.tableHeaderView = headerView;

}


- (BOOL)prefersStatusBarHidden

{

    return YES;

}


- (NSArray *)tgs

{

    if (_tgs == nil)

    {

        NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];

        NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];

        NSMutableArray *tgArray = [NSMutableArray array];

        for (NSDictionary * dict in dictArray)

        {

            CZTg *tg  = [CZTg tgWithDict:dict];

            [tgArray addObject:tg];

        }

        _tgs = tgArray;

    }

    return _tgs;

}


- (void)tgFooterViewDidClickLoadBtn:(CZTgFooterView *)tgFooterView

{

    CZTg *tg = [[CZTg alloc]init];

    tg.icon = @"2c97690e72365e38e3e2a95b934b8dd2";

    tg.title = @"新增加的数据";

    tg.price = @"100";

    tg.buyCount = @"10";

    NSMutableArray * array = [NSMutableArray arrayWithArray:self.tgs];

    [array addObject:tg];

    self.tgs = array;

    [self.tableView reloadData];

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return self.tgs.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    CZTgCell *cell = [CZTgCell cellWithTableView:tableView];

    cell.tg = self.tgs[indexPath.row];

    return cell;

}

@end 

posted @ 2015-08-10 22:01  我要选李白  阅读(151)  评论(0编辑  收藏  举报