IOS开发学习日记(二)

UIWindow

特殊形式的UIView,提供App中展示内容的基础窗口

只作为容器,和ViewController协同工作

通常在屏幕上只存在、展示一个UIWindow

使用storyBorad会自动创建

手动创建:
        1、创建UIWindow

        2、设置rootViewController

        3、makeKeyAndVisible

IOS常用设计模式:Delegate

点击后执行自定义的业务逻辑

//1、设置self为delegate的接收者
tabBar.delegate = self;
//2、根据需求按需实现方法
-(BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}
-(void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController{
    //播放该viewController的第一个视频
}

设计者:提供一些使用者可自定义的操作

                @optional/@required注解

                提供@property - delegate

                在对应的时机让delegate执行对应的方法

使用者:设置delegate=self

                按需实现方法

UITableView

列表

        特点:数据量大、样式统一、通常需要分组、垂直滚动、通常可视区只有一个——视图复用

UITableView作为视图只负责展示、协助管理,不管理数据

需要开发者为UITableView提供所需要的数据及Cell

通过delegate的模式,开发者需要实现UITableViewDataSource 

UITableViewCell默认提供展示文字和图片

UITableViewCell的重用

 滚动出页面的cell进入回收池,即将展现的cell从回收池中弹出。将所有cell的数量稳定在一定区间内。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return n;    //共n个cell
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id"];
    if (!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"id"];
    }
    
//    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"id"];
    
    cell.textLabel.text = @"主标题";
    cell.detailTextLabel.text = @"副标题";
    cell.imageView.image = [UIImage imageNamed:@"icon.bundle/video@2x.png"];
    return cell;
}

UITableViewDelegate

提供滚动过程中UITableViewcell的出现、消失时机

提供UITableViewCell的高度、headers以及footers设置

提供UITableViewCell各种行为的回调(点击、删除等)

UITableView基本使用

提供最基础的列表类型视图组件

提供默认基础的UITableViewCell样式、header和footer的管理

提供针对UITableViewCell的复用回收逻辑

提供列表基础功能,如点击、删除、插入等

        1、创建UITableView,设置delegate和datasource

        2、选择实现UITableViewDataSource中方法,行数、cell复用

        3、选择实现UITableViewDelegate中方法(高度、headerFooter、点击)

UICollectionView

提供列表展示的容器

内置复用回收池

相比于UITableView:

        支持横向+纵向布局

        更加灵活的布局方式

        更加灵活的动画

        更多的装饰视图

        布局之间的切换

与UITableVie有相同的Api设计理念——基于datasource以及delegate驱动

        由于一行能够战术多个视图,row无法表达。row -> item

        UICollectionViewDataSource

                numberOfItemsInSection:(NSInteger)section;

                cellForItemAtIndexPath:(NSIndexPath *)indexPath;

        UICollectionViewDelegate

                willDisplayCell / endDisplayCell ...

                -(void)collectionView:(UICollectionView *)collectionView

                  didSelectItemAtIndexPath:(NSIndexPath *)indexPath;

不提供默认样式:

        不是以“行”为设计基础

        只有contentView / backgroundView

        继承自UICollectionReusableView

必须先注册Cell类型用于重用

        1、-(void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;

        2、-(__kindof UICollectionViewCell *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;

UICollectionViewLayout

用于生成UIControllerView布局信息的抽象类

UICollectionViewFlowLayout流式布局,每一行排满后自动换行

        itenSize每个item的大小

        minimumInteritrmSpacing用于计算每行可以布局多少个item

        minimumLineSpacing行与行之间空隙距离

UICollectionViewDelegateFlowLayout

        根据indexPath做更细化的自定义样式

UICollectionView基本使用

1、创建UICollectionViewLayout,使用系统默认流式布局或自定义布局

2、创建UICollectionView,设置delegate和datasource,注册cell类型

3、选择实现UICollectionViewDataSource中方法,行数、cell复用

4、选择实现UICollectionViewDelegate中方法(点击、滚动等)

UITableView算得上是特殊Flow布局的UICollectionView

简单的列表仍然可以使用UITableView

有双向的布局,特殊布局等非普通场景(瀑布流、弹幕)需要使用UICollectionView

Layout切换,UICollectionView在选择屏幕时有动画过渡

  • 29
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我真的学不会了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值