• 【iOS入门】UITableView


    1.对应android ListView

    设计模式:都是适配器模式。android更明显,直接叫adapter. TableView使用协议。协议在android中就是接口。

    anroid 中给listview 一个适配器。tableview实现 UITableViewDelegate,UITableViewDataSource

    2.必须的实现协议方法

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UItableView 从该方法中获取数据。对应每行要显的内容。需要返回一个cell ;

    cell 类型是:UITableViewCell

    必须是这个。不能随便一个View。android是一个View就行,不管是啥 。

    3.重用机制 android 使用tag. UItableView两种方式,一个是注删一个ID,一个是给返回的Cell加一个id,再通过id取回来。

    id可是多个对应多种类型的cell 。

    //每行显示什么东西
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        
        if(indexPath.row %5 == 0 && indexPath.row>0){
            BigPictureTableViewCell* bigPicCell = [tableView dequeueReusableCellWithIdentifier:@"BigPictureTableViewCell"];
            if (bigPicCell == nil) {
                bigPicCell = [[BigPictureTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BigPictureTableViewCell"];
            }
            bigPicCell.title.text = @"驱动之家新闻-资讯中心 ——快科技-科技资讯专业发布平台";
            return bigPicCell;
        }else{
            TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
            if (cell == nil) {
                cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableViewCell"];
            }
            cell.title.text = @"家新闻-资讯中心 ——快科技-科技资讯专业发布平台";
            cell.secondTitle.text=@"科技(驱动之家旗下媒、游戏及产品资讯,是最及时权威的产业资讯及硬件资讯报道平台,快科技(驱动...";
            return cell;
        }
    }

    4.自定义Cell方法

    继承UITableViewCell往里加东西。加什么随便 。最后要放到 UITableViewCell.contentView里面。相当于根布局。ios没有布局的说法。都是frame绝对坐标。

    5.需要告诉系统每个cell的高度,这个有利绘制速度提高。这是android不同的地方。

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        if(indexPath.row%5==0 && indexPath.row>0){
            return 180;
        }
        return 81;
    }

    6.有header footer直接往里加就可以。代理接口。比如:

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
        return [self getHeaderView];
    }

    android 要把header设置到adapter里。由adapter管理。ios是回调接口。iso编程理念要原始得多水平不够代码耦合度会很高。给开发人员提出了更高要求。

    个人感觉android已应用了很多的设计模式,自然而成。

     

  • 相关阅读:
    哔哩哔哩小视频全栈爬取分析
    Python压缩指定文件及文件夹为zip
    python对字典及列表递归排序
    Python对list列表及子列表进行排序
    揭开yield关键字的神秘面纱
    python 发送email邮件带附件
    ElementNotVisibleException: Message: element not visible
    /usr/lib/python2.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version!
    selenium元素单击不稳定解决方法
    selenium自定义find_element
  • 原文地址:https://www.cnblogs.com/mamamia/p/12215126.html
Copyright © 2020-2023  润新知