1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #import "ViewController.h" #import "TG.h" #import "TgCell.h"
@interface ViewController () @property (nonatomic,strong) NSArray *tgs;
@end
@implementation ViewController
- (NSArray *)tgs { if (_tgs==nil) { _tgs=[TG tgs]; } return _tgs; } -(void)viewDidLoad { [super viewDidLoad]; self.tableView.rowHeight=80; self.tableView.contentInset=UIEdgeInsetsMake(20, 0, 0, 0); } #pragma mark -数据源 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.tgs.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //1.可重用标识符 static NSString *ID=@"Cell"; //2.tableView查询可重用Cell TgCell *cell=[tableView dequeueReusableCellWithIdentifier:ID]; //3.如果没有可重用cell if (cell==nil) { cell=[[[NSBundle mainBundle]loadNibNamed:@"TgCell" owner:nil options:nil]lastObject]; } //4.设置cell内容 TG *tg=self.tgs[indexPath.row]; cell.titleLabel.text=tg.title; cell.iconView.image=[UIImage imageNamed:tg.icon]; cell.priceLabel.text=tg.price; cell.buyCountLabel.text=tg.buyCount; return cell; } @end
|