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 

转载于:https://www.cnblogs.com/lixiang2015/p/4719383.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值