2015年07月09日第七天笔记

团购思路归纳

1.自带cell

-(UITableViewCell *) tableView:(UITableView *)TableView cellforRowAtIndexPath:(NSIndexPath *)indexPath
{
    //定义一个静态标识(命名和业务逻辑有关)
    static NSString *ID = @“groupPusrchase”;
    //到缓冲池去取到
    UITabelView *cell = [TableView dequeueResuableCellWithIndentifier:ID];
    //判空是则创建
    if(cell == nil )
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    //取模型数据
    AMode *amode = self.arrayOfData[indexPath.row];
    //往cell控件里塞数据
    cell.imageView.image = +++;
    cell.taxtLabel.text = ++;
    cell.detailTextLabel.text = +++;
    //返回cell
}

2.用xib文件自定义cell,有xib对应的类解决方案:继承自UITableViewCell
思路整理:反推
首先在cellForRowAtIndexPath有明显的改动之处:不在控制器直接想cell控件塞数据
这是因为创建了一个自定义的cell类,于是向cell里放数据的形式放生里改变
改变:将从控制器中取到的模型数据,放到了cell的模型模型属性了
具体实现:
1)就是让定义的cell类,有个模型数据接收器,用来接收控制器(外界)传来的数据并进行处理
2)在cell类里定义个模型属性,然后重写这个属性的setter方法(.h)

@property(nonatomic,strong)HMTgModel *tgModel;

3)在setter方法里完成,对cell控件子控件的数据填充

-(void) setTgModel:(HMTgModel *)tgModel
{
    _tgModel = tgModel;//这句是为了和getter配套的标准写法
    self.子控件1.image=[UIImage imageNamed:tgModel.icon];
    self.子控件2.text = tgModel.titile;
    self.子控件3.text = [NSString stringWithFormat:@“¥%@”, tgModel.price];
}

4)为更好的保证子控件的私有性,将子控件定义在.m文件中 的延展类中,并且和xib文件的控件保持连线

5)xib文件通过在控制面板设置关联cell类,和连线关联

关于自定义代理的引入
1.引入之前 (将控制器类引入自定义的xib类中)
例子:模拟加载更多的数据
点击自定义控件的按钮后,自动生成一条记录,现在要把记录添加到原视图中

1)需要原视图的数组,滚动View在原视图,刷新视图表现在原视图,于是将原视图引入自定义控件类意味着这些条件都具备了。
为了更好的解决一个问题,在自定义类里面引入外界类,通过这个类,调用这个类提供的方法解决。

2)就是把控制器传给footerView.在footerView中调用控制器的loadMoreData方法

-(void)loadMoreData
{
    HMTgMode *tgModel = [[HMIgMode alloc] init];
    tgModel.icon = @“”;
    tgModel.tite
    [self.tgs addObject:tgModel]; 
    [self.tableView reloadData];
    NSIndexPath *indexPath =  [NSIndxPath indexPathForRow:self.tags.count-1 inSection:0];
    [self.tableView srcollToAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}

2 引入代理:减少Controller和footerView互相依赖,降低耦合性,
于是自定义的控件创建代理协议,定义代理属性,当发生事件的时候通知代理
为什么控件自己没有解决事件的能力。因为和代理交织的东西太多。代理解决起来,比较方便。
自定义的控件,只负责更好的展示数据,和样式
团购总结:
1)头部:只是简单的xib运用
2)中部:涉及到展示外界数据,引入重写setter方法
3)尾部:涉及加载新的数据,引入监听事件,进而引入代理

新浪微博思路归纳
1 、根据数据模型建立frame模型
之所以建立frame模型,是为了封装计算cell内各个控件位置的过程。这体现了OOP的编程思想!
在Frame模型中,各个控件的Frame会根据传递过来的数据模型进行计算设置,所以Frame模型中必须有一个数据模型属性,
且计算各个控件的frame的过程应该放在模型数据属性的set方法中,并且在这里计算出cell的高度

2、引入frame模型就是解决cell高度适配问题,但是完全可以写在cell类里类实现,但是为什么非得要引入一个frame模型类呢
主要原因是返回行高的的tableView代理方法,先于cell类对象的创建完成调用,这样,写在cell类里将不能计时被计算出来,
也就不能实时适配。
3.frame模型构建,基于问题,和方便以后的扩展,构建如下
1)在cell类里有个frame模型属性 行高的返回时机决定

2)在fram类有个数据模型属性 数据大小决定

4.外界控制器的改动,由以前定义一个存放数据模型的数组改为定义一个存放fram摸型的数组

8.控件大小的计算过程 在frame模型的数据模型数据的setter方法里
1)设置头像的frame
必备数据:填充值
X = 填充值;Y=填充值; W = 40;H=W;
2)设置名称
必备数据:文本真实宽度,真实高度 (动态的)
X = 头像右边X+填充值
Y = 头像下边Y+(头像高度-文本真实高度)*0.5
W= 文本真实宽度,H= 文本真实高度

文本所占最大范围的计算 boundingRectWithSize

名称最大范围参照值:CGSize nameSize = CGSizeMake(MAXFLOAt,MAXFLOAt);

CGSize maxNameSize = [self textWithString:self.microBlog.name andFont:[UIFont systemFontOfSize:17] maxSize:nameSize];

最终会调用一个boundingRectWithSize方法计算 

- (CGSize)textWithString:(NSString *)text andFont:(UIFont *)font maxSize:(CGSize )maxSize{

       NSDictionary *nameDict = @{NSFontAttributeName:font};

       return   [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nameDict context:nil].size;


}

3)设置Vip
X = 文本右边X + 填充数据
Y = 文本Y //和文本水平对齐
W = 15
H = W;
4)设置正文
参照值 :CGSize textSize = CGSizeMake(355, MAXFLOAT);
X = 头像X //和头像竖直对齐
Y = 头像下面Y + 填充数据
H = 正文真实高度,W=正文真实宽度

5.配图
1)要判断有无配图
有:
X = 文本X
Y = 文本下边Y+填充数据
W=100;
H=W;
2)计算cell高度=配图下边Y + 填充数据
无:
1)计算cell高度=文本下边Y + 填充数据

9.cell重用有个问题,就是当下条记录和取出来的cell的记录属性不一一匹配的时候,会导致保留取出记录的部分数据,因为不能完全覆盖掉。所以这个时候在赋值的时候,先清空。

细节归纳
1.当我创建一个xib类时,继承UITableViewCell
1)在.h文件中定义数据模型属性的强引用
2)在.m文件中类延展里定义子控件属性并连线
3)重写数据模型属性的setter方法,将数据塞入子空间中
4)注意这里为什么要在.h文件中定义数据模型属性,并在setter方法里赋值呢?
主要是为了以后好扩展:比如在需要利用操作数据时,可以通过子控件间接获得
5) 细节:1)设置xib文件继承xib类2)设置xib文件标识 用来作cell重用
6)当在控制器里创建cell的时候,应该从xib文件里加载

2.当我创建一个loadView时,继承UIView
1)当我处理加载菊花,和加载文字控件时,应该将它们存放在一个控件里,容易同时操控隐藏和消失
2)在.h文件中,只有代理属性和协议。注意协议方法的命名 参数至少要返回当前View类对象
3) 把加载按钮的点击方法放在xib类里 为了修改相应控件状态 并通知代理加载数据
4) 把菊花在面板上设置动画 behavior:Animating 或者代码实现:[self.菊花 startAnimating];[self.菊花 stopAnimating]

3.当我在外界控制器设置代理时
1)把代理协议引入
2)用xib文件创建一个对象,设置代理为当前控制器
3)这个对象赋给将tableView的尾部view tableFooterView
4) 将当前按钮传过去
5)延迟加载方法

 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       //       3.加载更多数据
              if ([self.delegate respondsToSelector:@selector(tgFooterViewDidClick:)]) {//先判断有没有实现
                      [self.delegate tgFooterViewDidClick:self];
              }

4.实现协议方法
1)创建一个对象数据
2)知识储备

//       2.刷新数据
       [self.tableView reloadData];
//       3.显示完整的加载的数据
       NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.tgs.count - 1 inSection:0];
       [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

5.头部图片轮播器分析
1.定义一个xib类,一个xib文件(scrollView,pageController,view1,view2,label 同级)
2.类里只提供从文件加载控件生成类对象的方法

+ (instancetype) groupBuyheaderView
{
    return [[[UINib nibWithNibName:@"CZGroupBuyHeaderView" bundle:nil] instantiateWithOwner:nil options:nil] lastObject];
}

3.图片加载放在- (void)awakeFromNib

4.类延展 滚动控件 页面控制 定时器

新浪微博细节归纳

5.创建cell的的时候,要自定义的类中中重写
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

6.创建cell的的时候,要将自定义的子控件添加到 self.contentView 里,记住先添加再作其他操作

团购代码复习
1、在外部—尾部自定义xib控件 实现加载bundle
1)外部代码

在viewDidLoad
LoadBtnView *loadBtnView = [[NSBundle mainBundle] loadNibNamed:@“loadView”owner:nil options:nil].lastObject;
LoadBtnView *loadBtnView = [[NSBundle mianBundle] loadNibNamed:@“loadView”owner:nil options:nil].lastObject;
LoadBtnView *loadBtnView = [[NSBundle mainBundle] loadNibNamed:@“loadView”owner:nil options:nil].lastObject;

指定代理:自定义的按钮在类里监听事件,监听到就交给代理处理 代理的指定放在外部,代理方法的实现在外部实现

self.tableView.tableFooterView = loadBtnView;//指定自定义的View
self.tableView.tableFooterView = loadBtnView;
self.tableView.tableHeaderView = loadBtnView;
self.tableView.tableHeaderView = loadBtnView;
self.tableView.tableHeaderView = loadBtnView;

滑动到指定位置
[self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.tableView sctollToRowAtIndexPath:IndexPath atScrollPosition:UITableVIewScrollPositionBottom animated:YES];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableVIewScrollPositionBottom animated:YES];
创建路径索引
NSIndexPath *indexPath = [NSIndexPath indexPath:self.array.count-1 inSection:0];
NSIndexPath *indexPath = [NSIndexPath indexPath:self.array.count -1 inSection:0];
NSIndexPath *indexPath = [NSIndexPath indexPath:self.array.count -1 inSection:0];
NSIndexPath *indexPath = [NSIndexPath indexPath:self.array.count - 1 inSection:0];

在自定义头部类,实现-(awakeFromNib)
-(void)awakeFromNib
{
    CGFloat imageW = self.scrollImageView.frame.size.width;
    CGFloat imageH = self.scrollImageView.frame.size.height;
    self.scrollImageView.conentSize = CGSizeMake(count * imageW,0);
      self.scrolIImageView.contentSize = CGSizeMake(count * imageW,0);
    self.sccrollImageView.contetSize = CGSizeMake(count *imageW,0);
    //设置是否分页
    self.scrollImageView.pagingEnabled = YES;
    self.scrollimagView.pagingEnabled = YES;
    self.scrollimagView.pagingEnabled = YES//设置是否显示水平滚动条
    self.srcollimageView.showsHorizontablScrollIndicator = NO;
    self.srcollimageView.showsHorizontalScrllIndicator = NO;
    self.scrollimageView.showsHorizontalScrollIndicator = NO;
}
//定义定时器
NSTimer *timer = [NSTimer timeWithTimeInterval:2 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
NSTimer *timer = [NSTimer timeWithTimeInterval:2 target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
NSTimer *timer = [NSTimer timeWithTImeInterval:2 target:self selector:@selector(nextImage) userinfo:nil repeats:YES];
NSTimer *timer = [NSTimer timeWithTimerInterval:2 target:self selector:@selector(nextImage) userInfo:nil repeats:YES]

//加入主运行循环
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
self.timer = timer;

终止时间
[self.timer invalidate];
[self.timer invalidate];
[self.timer invalidate];
[self.timer invalidate]

获取页面控件的当前页

self.pageControl.currentPage;
self.pageCOntro.currentPage;
self.pageControl.currentPage;

设置滚动控件移动的位置
[self.scrollImageView setContentOffset:CGPointMake(x,y) animatied:YES];
[self.scrollImageViw setContentOffset:CGPointMake(x,y) animated:YES];
[self.scrollImageView setContentOffset:CGPointMake(x,y) animates:YES];

当开始滚动时
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
-(void)scrollViewWillBeginDragging:(UIscrollView *)scrollView
-(void)scrollViewWillBeginDragging:(UIScrollView *)scollView

当滚动结束时
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
-(void)scrollViewDidScroll:(UIScrollView *)scrolView;

当拖动后手指离开鼠标时
-(void)scrollViewDidEndDecelerating:(UIScrollView)scrollView

回顾:.在控制器里到plist取数据,就是在重写模型属性的getter方法的时候

-(NSArray *)模型数据属性
{
    if(_模型数据属性 == nil)
    {
        1、从文件里返回数组
        NSArray * dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResuorse:@"A.plist" ofType:nil];
        2.文件数组转换为模型数组
        NSMutableArray *tempArray = [NSMutableArray array];
        for(NSDictionary *dict in dictArray)
        {
           AMode *amode = [AMode amodeWithDict:dict];
           [tempArray addObject:amode];
        }
         _模型数据属性 = tempArray;
    }
      return _模型数据属性;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值