<span style="font-size:24px;color:#cc6600;">SecondViewController</span>继承了许多的类:

               CAViewController,  视图控制类
               CATableViewDataSource, tableView数据控制类
               CATableViewDelegate,   tableView事件代理     
               CAScrollViewDelegate   scrollView事件代理
实现了许多虚函数方法,和定义了一些私有变量
        CADipSize size;      //视图大小
<span style="white-space:pre"> </span>CATableView* p_TableView;  //一个tableView,用来创建
<span style="white-space:pre"> </span>int sect[NUM];             //#define NUM 8 一个sect数组
<span style="white-space:pre"> </span>CADeque<Info*> personList; // 一个CADeque<Info*>
<span style="white-space:pre"> </span>bool isPullUpRefresh;
         

首先还是来看ViewDidLoad() 这个方法,方法主要是加载一些视图控件

<pre name="code" class="cpp">void SecondViewController::viewDidLoad(){loadJsonData();//上下刷新视图的创建CAPullToRefreshView* headerRefreshView = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeHeader);CAPullToRefreshView* footerRefreshView = CAPullToRefreshView::create(CAPullToRefreshView::CAPullToRefreshTypeFooter);//创建了一个tableView,tableView每一行只有一个cellp_TableView = CATableView::createWithFrame(this->getView()->getBounds());p_TableView->setTableViewDataSource(this);  //设置数据代理p_TableView->setTableViewDelegate(this);    //设置事件处理p_TableView->setTableHeaderView(headerRefreshView); //设置头部刷新视图p_TableView->setTableFooterView(footerRefreshView); //设置尾部刷新视图p_TableView->setAllowsSelection(true);              //设置是否可选p_TableView->setScrollViewDelegate(this);           //设置scroll代理this->getView()->addSubview(p_TableView);           //添加进主视图
}

tableCellAtIndex这个方法是在tableview中创建创建

<pre name="code" class="cpp">CATableViewCell* SecondViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row){CCSize _size = cellSize;Info* p_List = (Info*)personList.at(row);//CADeque<Info*> personList中寻找第几号元素CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp");//寻找有没有"CrossApp"的cell,肯定是没有的所以每次都会进入ifif (cell==NULL){//_size.width*0.2, _size.height*0.5, _size.width*0.2, _size.heightcell = CATableViewCell::create("CrossApp");//创建CALabel* p_name=CALabel::createWithCenter(CCRect(_size.width*0.2, _size.height*0.5, _size.width*0.2, _size.height));//创建一个lablep_name->setTag(9);                        //设置标记p_name->setFontSize(_px(30));p_name->setColor(CAColor_blue);p_name->setTextAlignment(CATextAlignmentCenter);p_name->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);cell->addSubview(p_name);                 //添加进去   CALabel* p_num = CALabel::createWithCenter(CCRect(_size.width*0.4, _size.height*0.5, _size.width*0.2, _size.height));p_num->setTag(10);p_num->setFontSize(_px(30));p_num->setColor(CAColor_blue);p_num->setTextAlignment(CATextAlignmentCenter);p_num->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);cell->addSubview(p_num);CALabel* p_gender = CALabel::createWithCenter(CCRect(_size.width*0.6, _size.height*0.5, _size.width*0.2, _size.height));p_gender->setTag(11);p_gender->setFontSize(_px(30));p_gender->setColor(CAColor_blue);p_gender->setTextAlignment(CATextAlignmentCenter);p_gender->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);cell->addSubview(p_gender);CALabel* p_occupation = CALabel::createWithCenter(CCRect(_size.width*0.8, _size.height*0.5, _size.width*0.2, _size.height));p_occupation->setTag(12);p_occupation->setFontSize(_px(30));p_occupation->setColor(CAColor_blue);p_occupation->setTextAlignment(CATextAlignmentCenter);p_occupation->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);cell->addSubview(p_occupation);}CALabel* p_name = (CALabel*)cell->getSubviewByTag(9);    //获取label 标记p_name->setText(p_List->name.c_str());                   //设置label的数据类容,这样的数据类容肯定为空 CALabel* p_num = (CALabel*)cell->getSubviewByTag(10);p_num->setText(p_List->num.c_str());CALabel* p_gender = (CALabel*)cell->getSubviewByTag(11);p_gender->setText(p_List->gender.c_str());CALabel* p_occupation = (CALabel*)cell->getSubviewByTag(12);p_occupation->setText(p_List->occupation.c_str());return cell;}

接下来 personList 这个CADeque<Info*>数据从哪里来的

void SecondViewController::loadJsonData(void){Reader reader;Value value;//首先要找到一个名字叫做information.json文件,这个文件在source目录下string jsonFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("information.json");//把文件里的类容变成CCString 格式CCString* jsonData = CCString::createWithContentsOfFile(jsonFile.c_str());//解析这种格式,放入value中if (reader.parse(jsonData->getCString(),value)){//有一个Info.h类,里面有4个//std::string name;//std::string num;//std::string gender;//std::string occupation;int length = value["info"].size();for (int index = 0; index < length;index++){Info* personInfo = new Info();personInfo->autorelease();personInfo->name = value["info"][index]["name"].asString();personInfo->num = value["info"][index]["num"].asString();personInfo->gender = value["gender"].asString();personInfo->occupation = value["occupation"].asString();personList.pushBack(personInfo);  //放入personList}}
}

新手CrossApp 之demo SecondViewController小结相关推荐

  1. CrossApp 官方Demo

    Demo说明: Demo主要包含了CAScrollView.CATableView.CATabBarController.CANavigationController较为复杂的类的基本用法,同时也包含 ...

  2. 新手学Python, 如何从入门到入土变为从入门到快速上车?

    导读:今天这篇文章是「大数据DT」内容合伙人王皓关于<Python数据分析与数据化运营>的一篇读书笔记.在大数据公众号后台对话框回复合伙人,免费读书.与50万同行分享你的洞见. 本文旨在提 ...

  3. Dom4j 解析Xml文档及XPath查询 学习笔记

    本文查阅方法:     1.查阅目录 -- 查阅本文目录,确定想要查阅的目录标题     2.快捷"查找" -- 在当前浏览器页面,按键 "Ctrl+F" 按键 ...

  4. 关于用户表设计及多用户登入限制

    1.数据表设计 用户通用信息表 CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`nickname` varchar(32) NOT ...

  5. python爬虫从入门到精通-Python网络爬虫开发从入门到精通

    本书共分 3 篇,针对 Python 爬虫初学者,从零开始,系统地讲解了如何利用 Python 进行常见的网络爬虫的程序开发. 第 1 篇快速入门篇(第 1 章 ~ 第 9 章):本篇主要介绍了 Py ...

  6. AOP实现Android集中式登录架构

    未经同意禁止抄袭,如需转载请在显要位置标注 前言 登录应该是应用开发中一个很常见的功能,一般在应用中有两种登录,一种是一进入应用就必须登录才能使用(如微信和QQ等),另一种是需要登录的时候才会去登录( ...

  7. flutter 国际化_Flutter 开发实战资源推荐

    开工第一天,来点轻松的资源推荐. 这是一篇实战类资源推荐,其实Flutter的入门资料官方已经做得很好了,如果你是零基础,还是建议先啃一遍官方的教程,然后再看以下实战资源,相信在你看官方课程中涉及到的 ...

  8. 我的docker随笔7:docker容器与主机之间文件拷贝

    背景 Docker提供cp命令,用于主机和容器之间相互拷贝. docker cp命令 下面所有示例的命令都是在主机进行的. 命令形式如下: docker cp <主机目录或文件的路径> & ...

  9. 图像识别DM8127开发攻略——UBOOT的移植说明

    图像识别DM8127开发攻略--UBOOT的移植说明 根据前几篇文章的介绍,想必大家对DM8127软件架构有了全局的认识,下面我们从开发的角度进行裁剪移植最基本的BOOT软件包,嵌入式开发人员拿到一个 ...

  10. celery redis mysql_GitHub - FJUT/gxgk-wechat-server: 校园微信公众号后端,使用 Python、Flask、Redis、MySQL、Celery...

    This code is no longer being maintained. 项目已经不再维护,开源的目的更多是给新手一个参考 Demo gxgk-wechat-server 校园微信公众号后端, ...

最新文章

  1. JS document
  2. Power Shell02 认识powershell
  3. 微信、陌陌等著名IM软件设计架构详解【转】
  4. hdu2089 不要62 数位dp
  5. JZOJ 5941. 【NOIP2018模拟11.01】乘
  6. DotNetCore Web应用程序中的Cookie管理
  7. 【开源项目】基于Directx屏幕录制
  8. 【lua学习】4.表
  9. robo 3t连接_使用robo 3t studio 3t连接到地图集
  10. 统计文章中字母出现频率
  11. 开挂的印度裔00后:7岁“出道”教编程,12岁成为IBM荣誉顾问
  12. 特斯拉Autopilot系统被评为中国最佳驾驶辅助系统
  13. MySql Workbench表PK UN UQ B等字符的含义
  14. mybatisplus中的xml如何添加like条件,进行模糊查询
  15. opencv3编程入门-毛星云
  16. cacti监控linux和windows磁盘io,为CactiEZ(或者Cacti)增加监控磁盘IO功能
  17. 电路设计中发光二极管用作指示灯时的限流电阻如何选择
  18. 极大极小搜索 α-β剪枝的实现
  19. 「Cold Chain 2015国际冷链物流展」
  20. 汉字拼音的一个解决方法

热门文章

  1. 2022年计算机二级Access数据库程序设计复习题及答案
  2. pantum打印机驱动安装m6506_奔图Pantum M6506NW 驱动
  3. 彻底格式化系统启动U盘(基于win10)
  4. 基于微信小程序的校园论坛系统开发过程
  5. flutter框架优缺点,flutter开发的app有哪些
  6. input 文件提交 按钮制作
  7. NANDFlash原理
  8. SIM900A—发送、接收中英文短信
  9. 泰坦尼克号的数据分析
  10. 淘宝镜像(浏览器驱动等等等)