这段时间不断的被俗事缠身,公司的事儿也比较多,加之回家耽误了半个月的时间,本来4天的课程拖到现在才看完。离第06天的学习已经过去一个多月了,真是罪过,罪过!
不管现实怎样,我还是一如既往的保持对iOS的学习热情,今天是刚好坚持学习iOS八个整的时间,想想自己这八个月以来,几乎是放弃了所有的休息娱乐时间,来学习iOS周末也不出去玩,也不再去逛商城超市,彻底的变成了宅男一个,原本计划找女朋友的事儿,也因此一再的耽搁,因为每天一方面要做好公司的事儿,另一方面还要努力照顾到iOS的学习,导致每天身体都极度的贫乏,头发也因此掉了不少,总之跟2014刚来北京相比完全不是一种状态。
但是我不认为我所付出的心血是白费的,即使将来我iOS没有更换工作成功或者说更换成功后所得到的薪水不是自己满意的,我也毫无后悔无言,因为在坚持学习iOS的这段时间里我深深明白了一些道理,那就是人定胜天,只要努力,不急不躁,时时刻刻想着目标并为之踏实的行动,一定可以达到自己想要的结果,对此我深信不疑。
以下是第07天知识梳理:
1、
//当xib中的控件加载完成会调用此方法
- (void)awakeFromNib
{
CGFloat iconW = self.scrollView.frame.size.width;
CGFloat iconH = self.scrollView.frame.size.height;
for (int i = 0; i < 5; i++) {
NSString *imgName = [NSString stringWithFormat:@"ad_%02d",i];
UIImageView *iconView = [[UIImageView alloc] init];
[self.scrollView addSubview:iconView];
iconView.image = [UIImage imageNamed:imgName];
CGFloat iconX = i * iconW;
CGFloat iconY = 0;
iconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
}
self.scrollView.contentSize = CGSizeMake(5 * iconW, 0);
}
//延时执行
// [self performSelector:<#(SEL)#> withObject:<#(id)#> afterDelay:<#(NSTimeInterval)#>];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.loadMoreBtn.hidden = NO;
self.loadMoreView.hidden = YES;
//3 向代理对象发送消息
if ([self.delegate respondsToSelector:@selector(footerViewDidClickedLoadMoreBtn:)]) {
[self.delegate footerViewDidClickedLoadMoreBtn:self];
}
});
footerView.loadMoreBtn.layer.cornerRadius = 5;
footerView.loadMoreBtn.layer.masksToBounds = YES;
//创建自定义可重用的cell对象,(一般创建方法)
+ (instancetype)groupBuyingCellWithTableView:(UITableView *)tableView
{
static NSString *reuseId = @"gb";
CZGroupBuyingCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CZGroupBuyingCell" owner:nil options:nil] lastObject];
}
return cell;
}
//重写属性的setter方法,给子控件赋值,
- (void)setGroupBuying:(CZGroupBuying *)groupBuying
{
_groupBuying = groupBuying; 这一步很重要
self.titleView.text = groupBuying.title;
self.priceView.text = [NSString stringWithFormat:@"¥ %@",groupBuying.price];
self.buyCountView.text = [NSString stringWithFormat:@"%@人已购买",groupBuying.buyCount];
self.iconView.image = [UIImage imageNamed:groupBuying.icon];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//1 创建可重用的自定义的cell
CZGroupBuyingCell *cell = [CZGroupBuyingCell groupBuyingCellWithTableView:tableView];
//2 设置cell内部的子控件
CZGroupBuying *gb = self.groupBuyings[indexPath.row];
cell.groupBuying = gb;
//3 返回
return cell;
}
- (instancetype)initWithDic:(NSDictionary *)dic
{
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dic];
}
return self;
}
+ (instancetype)microBlogWithDic:(NSDictionary *)dic
{
return [[self alloc] initWithDic:dic];
}
+ (NSArray *)microBlogsList
{
//加载plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"microblog" ofType:@"plist"];
NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
//字典转模型
NSMutableArray *tmpArray = [NSMutableArray array];
for (NSDictionary *dic in dicArray) {
CZMicroBlog *microBlog = [CZMicroBlog microBlogWithDic:dic];
[tmpArray addObject:microBlog];
}
return tmpArray;
}
//1 懒加载
- (NSArray *)microBlogFrames
{
if (!_microBlogFrames) {
//加载模型数据
NSArray *microBlogs = [CZMicroBlog microBlogsList];
NSMutableArray *frames = [NSMutableArray array];
for (CZMicroBlog *blog in microBlogs) {
//创建frame模型对象
CZMicroBlogFrame *frame = [[CZMicroBlogFrame alloc] init];
frame.microBlog = blog;
//
[frames addObject:frame];
}
_microBlogFrames = frames;
}
return _microBlogFrames;
}
#pragma mark - tableView的代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CZMicroBlogFrame *frame = self.microBlogFrames[indexPath.row];
return frame.rowHeight;
}
重写构造方法,初始化(创建自定义cell内部的子控件)代码示范:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//创建子控件
//头像
UIImageView *iconView = [[UIImageView alloc] init];
[self.contentView addSubview:iconView];
self.iconView = iconView;
//昵称
UILabel *nameView = [[UILabel alloc] init];
[self.contentView addSubview:nameView];
self.nameView = nameView;
//
nameView.font = [UIFont systemFontOfSize:CZNameFont];
//会员
UIImageView *vipView = [[UIImageView alloc] init];
[self.contentView addSubview:vipView];
self.vipView = vipView;
self.vipView.image = [UIImage imageNamed:@"vip"];
//微博内容
UILabel *textView = [[UILabel alloc] init];
[self.contentView addSubview:textView];
self.textView = textView;
textView.font = [UIFont systemFontOfSize:CZTextFont];
textView.numberOfLines = 0;
//微博图片
UIImageView *pictureView = [[UIImageView alloc] init];
[self.contentView addSubview:pictureView];
self.pictureView = pictureView;
}
return self;
}
这一章掌握了不到%60,需要抽个时间好好复习下这章的学习内容,明天把懒加载,字典封装转模型等等不熟的地儿好好练习下吧。