当前位置:K88软件开发文章中心编程语言APP编程CrossApp → 文章内容

CATableView(表单视图)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:51:56

ze; //根据标识获得cell MyTableViewCell* cell = dynamic_cast<MyTableViewCell*>(table->dequeueReusableCellWithIdentifier("CrossApp")); //如果没有找到cell if (cell == NULL) { //创建一个 cell = MyTableViewCell::create("CrossApp", DRect(0, 0, _size.width, _size.height)); //调用cell的初始化 cell->initWithCell(); } //如果是section为1的情况 if (section == 1) { //根据tag获得CAButton CAButton* cellBtn = (CAButton*)cell->getSubviewByTag(102); //隐藏按钮 cellBtn->setVisible(false); } else { //根据tag获得CAButton CAButton* cellBtn = (CAButton*)cell->getSubviewByTag(102); //显示按钮 cellBtn->setVisible(true); } string order = crossapp_format_string("cell-%d",row); //根据tag获得CALabel CALabel* cellText = (CALabel*)cell->getSubviewByTag(100); //设置文本显示 cellText->setText(order); return cell;}CAView* FirstViewController::tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section){ CCLog("Header-->"); string head = crossapp_format_string("Selection-%d", section); //创建Section头部视图 CAView* view = CAView::createWithColor(CAColor_gray); DSize _size = viewSize; CALabel* header = CALabel::createWithCenter(DRect(_size.width*0.5, _size.height*0.5, _size.width*0.8, _size.height)); header->setText(head); header->setFontSize(_px(30)); header->setColor(CAColor_white); header->setTextAlignment(CATextAlignmentCenter); header->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); view->addSubview(header); return view;}CAView* FirstViewController::tableViewSectionViewForFooterInSection(CATableView* table, const DSize& viewSize, unsigned int section){ CCLog("Footer-->"); CAView* view = CAView::createWithColor(CAColor_white); return view;}unsigned int FirstViewController::numberOfRowsInSection(CATableView *table, unsigned int section){ //cell数,从0计算。10表示0-9 return 10;}unsigned int FirstViewController::numberOfSections(CATableView *table){ //表格数,从0开始计算。4则表示0-3 return 4;}unsigned int FirstViewController::tableViewHeightForRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row){ //高度 return _px(130);}unsigned int FirstViewController::tableViewHeightForHeaderInSection(CATableView* table, unsigned int section){ //高度 return _px(50);}unsigned int FirstViewController::tableViewHeightForFooterInSection(CATableView* table, unsigned int section){ return 1;}这样我们就构建了一个表格视图,大家可以自己尝试这用CATableVIew去实现一个微信的通信录列表。CATableView 属性说明TableViewDataSource类型:CATableViewDataSource*解释:添加数据代理。set/get{}。TableViewDelegate类型:CATableViewDelegate*解释:添加交互代理。set/get{}。TableHeaderView类型:CAView*解释:添加头部视图。set/get{}。TableFooterView类型:CAView*解释:添加尾部视图。set/get{}。SeparatorColor类型:CAColor4B解释:设置cell分割线的颜色。set/get{}。TableHeaderHeight类型:unsigned int解释:设置头部视图的高度。set/get{}。TableFooterHeight类型:unsigned int解释:设置尾部视图的高度。set/get{}。SeparatorViewHeight类型:unsigned int解释:设置cell分割线的高度。set/get{}。AllowsSelection类型:bool解释:是否开启cell选择。is{}。AllowsMultipleSelection类型:bool解释:是否可以多选cell。is{}。AlwaysTopSectionHeader类型:bool解释:设置cell顶部的标题。is/set{}。AlwaysBottomSectionFooter类型:bool解释:设置cell底部的标题。is/set{}。CATableView 方法说明virtual void setAllowsSelection(bool var);返回值:virtual void参数:类型参数名说明boolvar是否允许选择解释:是否开启cell选择virtual void setAllowsMultipleSelection(bool var);返回值:virtual void参数:类型参数名说明boolvar是否允许多个选择解释:是否可以多选cellvoid setSelectRowAtIndexPath(unsigned int section, unsigned int row);返回值:void参数:类型参数名说明unsigned intsectioncell所属的区域unsigned introwcell所在行数解释:设置选中cell时调用void setUnSelectRowAtIndexPath(unsigned int section, unsigned int row);返回值:void参数:类型参数名说明unsigned intsectioncell所属的区域unsigned introwcell所在行数解释:设置取消选中cell时调用virtual void setShowsScrollIndicators(bool var);返回值:virtual void参数:类型参数名说明boolvar是否设置显示滚动条解释:设置显示滚动条unsigned int getNumberOfSections();返回值:unsigned int参数:解释:获取tableview包含的section个数unsigned int getNumberOfRowsInSection(unsigned int section);返回值:unsigned int参数:类型参数名说明unsigned int sectioncell所属的区域解释:获取对应的section所包含的cell个数float getSectionHeightInSection(unsigned int section);返回值:float参数:类型参数名说明unsigned intsectioncell所属的区域解释:通过索引获取section高度float getSectionHeaderHeightInSection(unsigned int section);返回值:float参数:类型参数名说明unsigned intsectioncell所属的区域解释:通过section索引获取section顶部的高度float getSectionFooterHeightInSection(unsigned int section);返回值:float参数:类型参数名说明unsigned intsectioncell所属的区域解释

上一页  [1] [2] [3] [4] [5]  下一页


CATableView(表单视图)