CCTableView的使用和注意事项
#include "cocos-ext.h"
using namespace cocos2d::extension; class TableViewTestLayer: public CCTableViewDataSource, public CCTableViewDelegate
{
public:
///////////////////////////////////////////////////////////////////////////////////////////
// CCScrollViewDelegate
virtual void scrollViewDidScroll(CCScrollView* view){}
virtual void scrollViewDidZoom(CCScrollView* view){}
// CCTableViewDelegate
//点击响应
virtual void tableCellTouched(CCTableView* table, CCTableViewCell* cell){}
//设置按下时高亮
virtual void tableCellHighlight(CCTableView* table, CCTableViewCell* cell){}
//设置松开是取消高亮
virtual void tableCellUnhighlight(CCTableView* table, CCTableViewCell* cell){}
//循环使用某个单元格
virtual void tableCellWillRecycle(CCTableView* table, CCTableViewCell* cell){}
// CCTableViewDataSource
//每一项的大小
virtual CCSize tableCellSizeForIndex(CCTableView *table, unsigned int idx);
//每一项的内容
virtual CCTableViewCell* tableCellAtIndex(CCTableView *table, unsigned int idx);
//一共多少项
virtual unsigned int numberOfCellsInTableView(CCTableView *table);
/////////////////////////////////////////////////////////////////////////////////////////// protected:
CCTableView *mTableView;
};
//
mTableView = CCTableView::create(this, CCSizeMake(616, 551));
//设置左右滑动 或上下
mTableView->setDirection(kCCScrollViewDirectionVertical);
//
mTableView->setPosition(ccp(12, 851-770));
mTableView->setDelegate(this);
//index0123...由上到下放置
mTableView->setVerticalFillOrder(kCCTableViewFillTopDown);
mBg->addChild(mTableView); //
CCTableViewCell* TableViewTestLayer::tableCellAtIndex(CCTableView *table, unsigned int idx)
{
CCTableViewCell *pCell = table->dequeueCell();
if (! pCell )
{
pCell = new CCTableViewCell();
pCell ->autorelease(); //添加该项内容、、、、
}
else
{
//该项已有内容,服用之前滑出可视区域的tablecell,要么全部移除重新添加,要么自己更新、、、、
}
}
值得注意的是:
1. tableView在setVerticalFillOrder时会reloadData;
void CCTableView::setVerticalFillOrder(CCTableViewVerticalFillOrder fillOrder)
{
if (m_eVordering != fillOrder) {
m_eVordering = fillOrder;
if (m_pCellsUsed->count() > 0) {
this->reloadData();
}
}
}
所以--->要是在tableCellAtIndex中使用tableView的parent,记得先parent->addchild(tableveiw);再setVerticalFillOrder
2.tableView在create的时候,就会预加载一下tableCell,调用updateCellAtIndex,下面是调用CCTableView::create的调用堆栈

所以--->要是在updateCellAtIndex中涉及到tableView的parent调用,程序就会蹦掉、
所以最好将create出来的tableView保存为成员变量,然后在updateCellAtIndex中判断一下
CCTableViewCell *cell = table->dequeueCell(); if (cell == NULL)
{
cell = new CCTableViewCell();
cell->autorelease();
}
else
{
cell->removeAllChildren();
} //如果不是create保存的成员变量(即此时调用的updateCellAtIndex是在create是预加载调用的),则不要涉及到parent的操作。
if (table != mTableView) return cell;
CCTableView的使用和注意事项的更多相关文章
- jQuery UI resizable使用注意事项、实时等比例拉伸及你不知道的技巧
这篇文章总结的是我在使用resizable插件的过程中,遇到的问题及变通应用的奇思妙想. 一.resizable使用注意事项 以下是我在jsfiddle上写的测试demo:http://jsfiddl ...
- Windows Server 2012 NIC Teaming介绍及注意事项
Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...
- TODO:Golang指针使用注意事项
TODO:Golang指针使用注意事项 先来看简单的例子1: 输出: 1 1 例子2: 输出: 1 3 例子1是使用值传递,Add方法不会做任何改变:例子2是使用指针传递,会改变地址,从而改变地址. ...
- app开发外包注意事项,2017最新资讯
我们见过很多创业者,栽在这app外包上.很多创业者对于app外包这件事情不是特别重视,以为将事情交给app外包公司就完事了,实际上不是的.无论是从选择app外包公司还是签订合同.售后维护等各方面都有许 ...
- favicon.ioc使用以及注意事项
1.效果 2.使用引入方法 2.1 注意事项:(把图标命名为favicon.ico,并且放在根目录下,同时使用Link标签,多重保险) 浏览器默认使用根目录下的favicon.ico 图标(如果你并没 ...
- ORACLE分区表梳理系列(二)- 分区表日常维护及注意事项(红字需要留意)
版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...
- 【原】Masonry+UIScrollView的使用注意事项
[原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...
- 《连载 | 物联网框架ServerSuperIO教程》- 5.轮询通讯模式开发及注意事项。附:网友制作的类库说明(CHM)
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- 《连载 | 物联网框架ServerSuperIO教程》- 6.并发通讯模式开发及注意事项
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
随机推荐
- The solution to Force.Com IDE 29.0 PassWord Problem
我最近使用Force.com IDE 时,经常提示密码错误.从Google 中终于发现一个解决方法,分享给大家,以供大家参考. 在Force.com IDE 29.0中,IDE 存储我们开发Org ...
- 【恒天云技术分享系列11】Sheepdog简介
sheepdog是近几年开源社区新兴的分布式块存储文件系统,采用完全对称的结构,没有类似元数据服务的中心节点.这种架构带来了线性可扩展性,没有单点故障和容易管理的特性.对于磁盘和物理节点,SheepD ...
- Delphi实例-IdTCPServer和IdTCPClient的使用(支持文件发送)
相关资料: http://blog.csdn.net/earbao/article/details/46514313 结果注意: 1.Use IdContext.IdGlobal 这两个单元2.不能使 ...
- HDU 5656 CA Loves GCD (数论DP)
CA Loves GCD 题目链接: http://acm.hust.edu.cn/vjudge/contest/123316#problem/B Description CA is a fine c ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- STL学习系列五:Queue容器
Queue简介 queue是队列容器,是一种“先进先出”的容器. queue是简单地装饰deque容器而成为另外的一种容器. #include <queue> 1.queue对象的默认构造 ...
- jsp页面显示数据库的数据信息表
在日常jsp开发中:最基本的一个操作之一是把之前添加到数据库中的信息在jsp页面中显示出来,也就是增删改查中的查找的一部分: 下面是以上部分的开发步骤及分析. 1.在jsp页面: <thead& ...
- Failed to execute query: Duplicate entry '0' for key 'PRIMARY'
今天在做php登陆和登出会插入数据到log表中,,结果报错了:如下: Failed to execute query: Duplicate entry '0' for key 'PRIMARY' SQ ...
- C# 调用第三方DLL完整实例
C# 调用第三方DLL完整实例 分类: C/C++ 以下代码为本人在实际项目中编写的调用第三方DLL接口程序的完整代码. public class ExecuteDLL : Form { ...//忽 ...
- Ehcache(01)——简介、基本操作
http://haohaoxuexi.iteye.com/blog/2112170 目录 1 CacheManager 1.1 构造方法构建 1.2 静态方法构建 2 ...