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

CATableView(表单视图)

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

小 DSize m_size = this->getFrame().size; //创建CALabel CALabel* cellText = CALabel::createWithCenter(DRect(m_size.width*0.1, m_size.height*0.5, m_size.width*0.3, m_size.height*0.8)); //设置tag cellText->setTag(100); //设置字体大小 cellText->setFontSize(_px(30)); //设置中心对齐 cellText->setTextAlignment(CATextAlignmentCenter); cellText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); //添加到当前cell this->addSubview(cellText); //创建CAButton CAButton* btnOnCell = CAButton::createWithCenter(DRect(m_size.width*0.85, m_size.height*0.5, m_size.width*0.2, m_size.height*0.7), CAButtonTypeRoundedRect); //设置tag btnOnCell->setTag(102); //设置显示文本 btnOnCell->setTitleForState(CAControlStateAll, "Touch"); //添加回调监听 btnOnCell->addTarget(this, CAControl_selector(MyTableViewCell::cellBtnCallback), CAControlEventTouchUpInSide); //添加到cell this->addSubview(btnOnCell);}void MyTableViewCell::cellBtnCallback(CAControl* btn, DPoint point){ //按钮被点击时打印log CCLog("MyTableViewCell::cellBtnCallback-->");}void MyTableViewCell::normalTableViewCell(){ //改变背景颜色 this->setBackgroundView(CAView::createWithColor(CAColor_white));}void MyTableViewCell::highlightedTableViewCell(){ //改变背景颜色 this->setBackgroundView(CAView::createWithColor(CAColor_gray));}void MyTableViewCell::selectedTableViewCell(){ //改变背景颜色 this->setBackgroundView(CAView::createWithColor(CAColor_orange));}void MyTableViewCell::disabledTableViewCell(){ //改变背景颜色 this->setBackgroundView(CAView::createWithColor(CAColor_black));}void MyTableViewCell::recoveryTableViewCell(){ //改变背景颜色 this->setBackgroundView(CAView::createWithColor(CAColor_blue));}我们创建了cell之后,就在FirstViewController实现CATableViewDelegate和CATableViewDataSource这两个代理,那么FirstViewController.h的内容如下:#ifndef __HelloCpp__ViewController__#define __HelloCpp__ViewController__#include <iostream>#include "CrossApp.h"#include "MyTableViewCell.h"USING_NS_CC;class FirstViewController: public CAViewController , public CATableViewDataSource ,public CATableViewDelegate{ public: FirstViewController(); virtual ~FirstViewController(); public: //选中cell时触发 virtual void tableViewDidSelectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row); //取消选中cell时触发 virtual void tableViewDidDeselectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row); //获取对应的section所包含的cell个数 virtual unsigned int numberOfRowsInSection(CATableView *table, unsigned int section); //获取tableview包含的section个数 virtual unsigned int numberOfSections(CATableView *table); //获得指定cell virtual CATableViewCell* tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row); //设置section的头部 virtual CAView* tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section); //设置section的尾部 virtual CAView* tableViewSectionViewForFooterInSection(CATableView* table, const DSize& viewSize, unsigned int section); //获取指定的cell高度 virtual unsigned int tableViewHeightForRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row); //获得指定的section的header vier的高度 virtual unsigned int tableViewHeightForHeaderInSection(CATableView* table, unsigned int section); //获得指定的section的footer view的高度 virtual unsigned int tableViewHeightForFooterInSection(CATableView* table, unsigned int section); protected: void viewDidLoad(); void viewDidUnload(); };#endif /* defined(__HelloCpp__ViewController__) */然后我们在FirstViewController.cpp中实现表格视图如下:#include "FirstViewController.h"FirstViewController::FirstViewController(){}FirstViewController::~FirstViewController(){}void FirstViewController::viewDidLoad(){ DSize size = this->getView()->getBounds().size; CATableView* p_TableView = CATableView::createWithCenter(DRect(size.width*0.5, size.height*0.5, size.width, size.height)); p_TableView->setTableViewDataSource(this); p_TableView->setTableViewDelegate(this); p_TableView->setAllowsSelection(true); p_TableView->setAllowsMultipleSelection(true); p_TableView->setSeparatorColor(CAColor_clear); this->getView()->addSubview(p_TableView);}void FirstViewController::viewDidUnload(){ // Release any retained subviews of the main view. // e.g. self.myOutlet = nil;}void FirstViewController::tableViewDidSelectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row){}void FirstViewController::tableViewDidDeselectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row){}CATableViewCell* FirstViewController::tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row){ DSize _size = cellSi

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


CATableView(表单视图)