新手CrossApp 之demo SecondViewController小结
来源:互联网 发布:淘宝包邮拒签邮费谁出 编辑:程序博客网 时间:2024/05/17 13:40
<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}}}
0 0
- 新手CrossApp 之demo SecondViewController小结
- [寒江孤叶丶的CrossApp之旅_11][入门系列]通过Demo学习CrossApp之SecondViewController篇
- 新手CrossApp 之CAAlertView小结
- 新手CrossApp 之CAbutton小结
- 新手CrossApp 之CollectionView小结
- 新手CrossApp 之IndicatorView小结
- 新手CrossApp 之ScrollView小结
- 新手CrossApp 之ListView小结
- 新手CrossApp 之CASlider小结
- 新手CrossApp 之CAProgress小结
- 新手CrossApp 之CASegmentControl小结
- 新手CrossApp 之CATabBarController,CANavigationBarController,CADrawerController小结
- CrossApp
- 新手上路之AJAX AJAX笔记小结
- CrossApp之 获取当前系统时间
- [寒江孤叶丶的CrossApp之旅_01]CrossApp在MAC下的环境搭建
- [寒江孤叶丶的CrossApp之旅_02]CrossApp如何创建一个新的工程
- [寒江孤叶丶的CrossApp之旅_04][入门系列]修改CrossApp默认打开的Window(窗口)
- Android开发,项目中实现的摇一摇功能。使用加速度传感器SensorEventListener
- U盘文件只读的解决办法
- 外挂技术研究-封装动作数组功能
- 黑马程序员——String类
- python获取本机IP、mac地址、计算机名
- 新手CrossApp 之demo SecondViewController小结
- C/C++切割字符串
- 黑马程序员-IOS学习笔记-C语言基础其他数据类型及总结
- “奥运故事”是最好的励志教育
- Using on() instead of bind() live() and delegate()
- 外挂技术研究-封装完善动作使用CALL-重复包含头文件
- 2012杭电 素数判定
- android调试出现E/AndroidRuntime(13678): java.lang.NoClassDefFoundError:
- 《linux终端,会话组,进程组,作业,进程》