iOS开发总结之自定义等高cell-storyboard
2016-04-14 00:28
453 查看
1.storybord中添加子控件并设置tag
2.代码:
#import "XMGDealsViewController.h" #import "XMGDeal.h" @interface XMGDealsViewController () /** 所有的团购数据 */ @property (nonatomic, strong) NSArray *deals; @end @implementation XMGDealsViewController - (NSArray *)deals { if (_deals == nil) { // 加载plist中的字典数组 NSString *path = [[NSBundle mainBundle] pathForResource:@"deals.plist" ofType:nil]; NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 字典数组 -> 模型数组 NSMutableArray *dealArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { XMGDeal *deal = [XMGDeal dealWithDict:dict]; [dealArray addObject:deal]; } _deals = dealArray; } return _deals; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.deals.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *ID = @"deal"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // 取出模型数据 XMGDeal *deal = self.deals[indexPath.row]; // 设置数据 UIImageView *iconView = (UIImageView *)[cell viewWithTag:10]; iconView.image = [UIImage imageNamed:deal.icon]; UILabel *titleLabel = (UILabel *)[cell viewWithTag:20]; titleLabel.text = deal.title; UILabel *priceLabel = (UILabel *)[cell viewWithTag:30]; priceLabel.text = [NSString stringWithFormat:@"¥%@", deal.price]; UILabel *buyCountLabel = (UILabel *)[cell viewWithTag:40]; buyCountLabel.text = [NSString stringWithFormat:@"%@人已购买", deal.buyCount]; return cell; } @end
3.效果:
相关文章推荐
- iOS并发编程技巧
- ios开发之导航控制器的原理
- iOS 'The sandbox is not sync with the Podfile.lock
- IOS 制作静态库的两种方法
- iOS 开发常用链接总结
- TableView的footerView不随cell滚动而停留在tableView底部的问题,ios tableviewfooter
- iOS - 百度地图
- 简单监测iOS卡顿的demo
- iOS crash分析
- iOS实现无限后台background的方法
- [IOS]Core Data简单实例(使用Xcode7)
- iOS有关横向TableView的东西
- iOS instruments介绍
- iOS 关联策略 详解
- iOS开发中遇到的常用的小知识
- iOS学习笔记之回调(二)
- iOS runtime 机制 通过别扩展category给一个类添加属性
- iOS代理
- iOS之AFN使用技巧(3)
- iOS 用 SDWebImage 清理图片缓存