IOS开发基础之团购案例17-xib和UITableView两种方式实现

Design By Johnson Shanghai
实现效果

系统和Xcode版本


注意的细节

关键性的代码

//
//  ViewController.m
//  17-团购案例
//
//  Created by 鲁军 on 2021/2/4.
//#import "ViewController.h"
#import "CZGoods.h"
#import "CZGoodsCell.h"@interface ViewController ()<UITableViewDataSource>@property(nonatomic,strong)NSArray *goods;
@property (weak, nonatomic) IBOutlet UITableView *tableView;@end@implementation ViewController- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{CZGoods *model = self.goods[indexPath.row];//    static NSString *ID= @"goods_cell";
//
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
//    if(cell==nil){//
//        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
//
//    }
//    cell.imageView.image = [UIImage imageNamed:model.icon];
//    cell.textLabel.text = model.title
//    ;
//    cell.detailTextLabel.text = [NSString stringWithFormat:@"¥ %@      %@人已购买",model.price,model.buyCount];CZGoodsCell *cell = [CZGoodsCell goodsCellWithTableView:tableView];cell.goods = model;return cell;}- (BOOL)prefersStatusBarHidden{return YES;
}//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{//    return  1;
//}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return self.goods.count;}- (NSArray *)goods{if(_goods==nil){NSString *path = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];NSArray *arrayDict = [NSArray arrayWithContentsOfFile:path];NSMutableArray *attayModles = [NSMutableArray array];for(NSDictionary *dict in arrayDict){CZGoods *model = [CZGoods goodsWithDict:dict];[attayModles addObject:model];}_goods = attayModles;}return _goods;
}
- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.self.tableView.rowHeight = 60;}@end
//
//  CZGoods.h
//  17-团购案例
//
//  Created by 鲁军 on 2021/2/4.
//#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface CZGoods : NSObject@property(nonatomic,copy)NSString *buyCount;
@property(nonatomic,copy)NSString *price;
@property(nonatomic,copy)NSString *title;
@property(nonatomic,copy)NSString *icon;-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)goodsWithDict:(NSDictionary *)dict;@endNS_ASSUME_NONNULL_END
//
//  CZGoods.m
//  17-团购案例
//
//  Created by 鲁军 on 2021/2/4.
//#import "CZGoods.h"@implementation CZGoods
-(instancetype)initWithDict:(NSDictionary *)dict{if(self=[super init]){[self setValuesForKeysWithDictionary:dict];}return self;
}
+(instancetype)goodsWithDict:(NSDictionary *)dict{return [[self alloc] initWithDict:dict];
}
@end
//
//  CZGoodsCell.h
//  17-团购案例
//
//  Created by 鲁军 on 2021/2/4.
//#import <UIKit/UIKit.h>NS_ASSUME_NONNULL_BEGIN@class CZGoods;
@interface CZGoodsCell : UITableViewCell@property(nonatomic,strong)CZGoods *goods;+(instancetype)goodsCellWithTableView:(UITableView *)tableView;@endNS_ASSUME_NONNULL_END
//
//  CZGoodsCell.m
//  17-团购案例
//
//  Created by 鲁军 on 2021/2/4.
//#import "CZGoodsCell.h"
#import "CZGoods.h"
//类扩展
@interface CZGoodsCell()
@property (weak, nonatomic) IBOutlet UIImageView *imgViewIcon;@property (weak, nonatomic) IBOutlet UILabel *lblTitle;@property (weak, nonatomic) IBOutlet UILabel *lblPrice;@property (weak, nonatomic) IBOutlet UILabel *lblBuyCount;@end@implementation CZGoodsCell
+ (instancetype)goodsCellWithTableView:(UITableView *)tableView{static NSString *ID= @"goods_cell";CZGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if(cell==nil){cell=[[[NSBundle mainBundle] loadNibNamed:@"CZGoodsCell" owner:nil options:nil] firstObject];}return cell;
}- (void)setGoods:(CZGoods *)goods{_goods = goods;self.imgViewIcon.image =[UIImage imageNamed:goods.icon];self.lblTitle.text=goods.title;self.lblPrice.text=[NSString stringWithFormat:@"¥ %@",goods.price];self.lblBuyCount.text=[NSString stringWithFormat:@"%@ 人已购买",goods.buyCount];}- (void)awakeFromNib {[super awakeFromNib];// Initialization code
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state
}@end

IOS开发基础之团购案例17-xib和UITableView两种方式实现相关推荐

  1. IOS开发基础之大转盘案例

    IOS开发基础之大转盘案例 本案例使用xib加载的,以及核心动画的使用.动态按钮的使用和创建.等知识. 源码在我的主页资源下.欢迎下载. 核心代码在这. // LJRotateView.h // 37 ...

  2. Android 应用开发 之通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比

    Android 应用开发 之通过AsyncTask与ThreadPool(线程池)两种方式异步加载大量数据的分析与对比 标签: AndroidAsyncTaskThreadPool异步加载view 2 ...

  3. iOS开发小技巧--边接受数据边写入文件的两种方法

    一.NSFileHanle 使用注意点:在往文件写入数据时,必须创建一个空的文件 指定文件写入的方式 -- 覆盖还是追加 最后记得关闭 <1>代码是在大文件传输的练习中截取的.写入数据之前 ...

  4. 驱动程序开发:基于EC20 4G模块自动拨号联网的两种方式(GobiNet工具拨号和PPP工具拨号)

    目录 一.EC20 4G模块简介 二.根据移远官方文档修改EC20 4G模组驱动   1.因为EC20 4G模组min-pice接口其实就是usb接口,因此需要修改Linux内核源码drivers/u ...

  5. Java并发基础01. 传统线程技术中创建线程的两种方式

    传统的线程技术中有两种创建线程的方式:一是继承Thread类,并重写run()方法:二是实现Runnable接口,覆盖接口中的run()方法,并把Runnable接口的实现扔给Thread.这两种方式 ...

  6. IOS开发基础之UI基础的团购源码完整版本

    IOS开发基础之UI基础的团购源码完整版本 // // ViewController.m // 17-团购案例 // // Created by 鲁军 on 2021/2/4. //#import & ...

  7. IOS开发基础之模拟科技头条项目案例32

    IOS开发基础之模拟科技头条项目案例32 说说这个项目的技术要点核心 ,首先是异步网络请求,block的回调,sdWebImage的使用.各个控件的使用,NSDate日期的转换.自动适配屏幕工作,模型 ...

  8. IOS开发基础之摇奖机案例

    IOS开发基础之摇奖机案例 // ViewController.m // 33-摇奖机器 // Created by 鲁军 on 2021/3/9. #import "ViewControl ...

  9. IOS开发基础之画板案例软件的开发

    IOS开发基础之画板案例软件的开发 值此元宵佳节,我依然在学习IOS,几天没有更新博客了.今天更新了一下. 源码在我的主页里面. info.plist里面加入这样的代码,防止截图的时候有问题 < ...

最新文章

  1. No access for action Display of object type Product (PRODUCT)
  2. 《c语言从入门到精通》看书笔记——第8章 数组
  3. signature=18441de5a4bb8df92eb5cf5dcca47d1e,Heroísmo y los medios de comunicación (Capítulo 5A 5B)...
  4. 【渝粤教育】国家开放大学2019年春季 1062文学英语赏析 参考试题
  5. HDU 2234 IDA*
  6. Xcode7 添加PCH文件
  7. 简单易懂的破解脱壳从0开始
  8. C语言窗口布局,Android开发入门之学习笔记(四):程序窗口的布局(二)
  9. 分布式链路追踪技术对比
  10. C#中的文件流和文本流
  11. python 日期排序_python 日期排序
  12. java循环取出word table表格中所有的值
  13. python训练营 朋友圈点赞收费吗_微信朋友圈点赞,是不是扣话费?有人给
  14. 从头开发一个Flutter插件(一)开发流程
  15. XP桌面背景文件路径
  16. Re:从0开始的微服务架构:(一)重识微服务架构
  17. SQL性能优化以及性能测试
  18. 北洋网络口打印机设置
  19. python录音详解_Python爬虫实战案例:取喜马拉雅音频数据详解
  20. 瞬时频率函数matlab,Hilbert 变换与瞬时频率

热门文章

  1. 一维有限元法matlab,一维有限元法解常微分方程
  2. java 输出编码_从代码看java输入输出中的编码和解码
  3. html怎么在图片上加文字_怎么把图片文字转换成word文档
  4. python自动化框架2019_【转】python3实现自动化框架robotframework
  5. python直接使用pyc_Pyc和pyo是怎样一种存在?
  6. 自制一个害羞的口罩,见人就闭嘴,戴着可以喝奶茶
  7. 工作群里常见表情的真正含义……
  8. git branch 为什么会进入编辑状态_最好的Git分支管理教程
  9. lrange是取出所有值并移除么_美欧日站点亚马逊物流库存绩效指标分数达标值将降低为 450...
  10. java 输出ssl握手信息_使用Java的SSL握手错误