iOS开发总结之自定义等高cell03-xib
2016-04-14 13:17
459 查看
1.nib中的结构
2.代码封装上面的cell
#import "XMGDealsViewController.h" #import "XMGDeal.h" #import "XMGDealCell.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]; // UINib *nib = [UINib nibWithNibName:NSStringFromClass([XMGDealCell class]) bundle:nil]; // [self.tableView registerNib:nib forCellReuseIdentifier:@"deal"]; // [self.tableView registerClass:[XMGDealCell class] forCellReuseIdentifier:@"deal"]; } - (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 { // 创建cell XMGDealCell *cell = [XMGDealCell cellWithTableView:tableView]; // 取出模型数据 cell.deal = self.deals[indexPath.row]; return cell; } @end
效果:
相关文章推荐
- FFmpeg在iOS mac 终端上下载
- iOS开发获取系统表情
- iOS runtime运行机制
- iOS编程--AVCapture编程理解--自定义相机
- IOS开发语言OC的基本语法以及结构
- iOS的Target-Action模式传值的最佳方式
- 在 iOS 上捕获视频
- iOS 设置启动图片
- iOS 视频相关
- IOS Quartz2D简介
- iOS 自动布局库 SDAutoLayout
- IOS 对象的归档与解档
- iOS 局部变量 setTag后可在别的地方调用 viewWithTag
- ios配置xmpp即时聊天-服务器端
- iOS - GCD 之线程死锁
- Masonry教程--IOS自适配,丢掉Autolayout吧
- iOS解决navigationBar因为图片尺寸问题造成的会向上偏移64的问题
- iOS开发之友盟推送配置教程
- IOS Crash捕获
- iOS 拍照保存到相册