類說(shuō)明
CATableView 主要用于生成列表,在table中展示數(shù)據(jù),是一個(gè)一維的表,可以讓用戶能通過(guò)分層的數(shù)據(jù)進(jìn)行導(dǎo)航,表可以是靜態(tài)的或者動(dòng)態(tài)的,可通過(guò) dataSource 協(xié)議和 delegate 協(xié)議可以實(shí)現(xiàn)很多的個(gè)性化定制,即便擁有大量數(shù)據(jù)也非常有效率。CATableView只能有一列數(shù)據(jù)(cell),且只支持縱向滑動(dòng)。
我們先了解一下CATableView的界面構(gòu)成,CATableView主要是由兩級(jí)目錄構(gòu)成Selection級(jí)和Cell級(jí)。如圖所示,一個(gè)CATableView包含一個(gè)或多個(gè)Selection,一個(gè)Selection包含一個(gè)或多個(gè)Cell,這樣就構(gòu)成了CATableVIew的層級(jí)表示圖。
CATableView的使用方法和CAListView比較類似,我們也要分別使用:CATableView、CATableViewCell、CATableViewDelegate、CATableViewDataSource來(lái)構(gòu)建。
CATableView是表格視圖的容器,是容器的載體。
CATableViewCell是表格視圖的一個(gè)單元(本節(jié)后面簡(jiǎn)稱cell)。
CATableViewDelegate是交互代理,響應(yīng)cell選中和取消狀態(tài)。
CATableViewDataSource是數(shù)據(jù)代理,設(shè)置Selection個(gè)數(shù)及Selection包含cell個(gè)數(shù)。
CATableView 屬性(點(diǎn)擊查看方法介紹)
屬性 | 說(shuō)明 |
TableViewDataSource | 添加數(shù)據(jù)代理 |
TableViewDelegate | 添加交互代理 |
TableHeaderView | 添加頭部視圖 |
TableFooterView | 添加尾部視圖 |
SeparatorColor | 設(shè)置cell分割線的顏色 |
TableHeaderHeight | 設(shè)置頭部的高度 |
TableFooterHeight | 設(shè)置尾部的高度 |
SeparatorViewHeight | 設(shè)置cell分割線的高度 |
AllowsSelection | 是否開啟cell選擇 |
AllowsMultipleSelection | 是否可以多選cell |
AlwaysTopSectionHeader | 設(shè)置cell頂部的標(biāo)題 |
AlwaysBottomSectionFooter | 設(shè)置cell底部的標(biāo)題 |
CATableView 方法(點(diǎn)擊查看方法介紹)
方法 | 說(shuō)明 |
setAllowsSelection | 是否開啟cell選擇 |
setAllowsMultipleSelection | 是否可以多選cell |
setSelectRowAtIndexPath | 設(shè)置選中cell時(shí)調(diào)用 |
setUnSelectRowAtIndexPath | 設(shè)置取消選中cell時(shí)調(diào)用 |
setShowsScrollIndicators | 設(shè)置顯示滾動(dòng)條 |
getNumberOfSections | 獲取tableview包含的section個(gè)數(shù) |
getNumberOfRowsInSection | 獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù) |
getSectionHeightInSection | 通過(guò)索引獲取section高度 |
getSectionHeaderHeightInSection | 通過(guò)索引獲取section頂部的高度 |
getSectionFooterHeightInSection | 通過(guò)索引獲取section底部的高度 |
getRowHeightInSectionInRow | 通過(guò)索引cell高度獲取section和cell |
createWithFrame | 創(chuàng)建,并指定其Frame,默認(rèn)Frame為(0,0,0,0) |
createWithCenter | 創(chuàng)建,并指定其Center,默認(rèn)Center為(0,0,0,0) |
dequeueReusableCellWithIdentifier | 可以重用單元標(biāo)示符 |
cellForRowAtIndexPath | 通過(guò)索引cell獲取Index路徑 |
switchPCMode | 開關(guān)PC模式 |
ccTouchBegan | 觸摸事件開始時(shí)的回調(diào)函數(shù) |
ccTouchMoved | 觸摸事件中觸點(diǎn)移動(dòng)時(shí)的回調(diào)函數(shù) |
ccTouchEnded | 觸摸事件結(jié)束時(shí)的回調(diào)函數(shù) |
ccTouchCancelled | 觸摸非正常結(jié)束時(shí)的回調(diào)函數(shù)。(例如:電話或鎖屏) |
mouseMoved | 鼠標(biāo)移動(dòng) |
mouseMovedOutSide | 鼠標(biāo)移出 |
init | 初始化 |
reloadData | 重載數(shù)據(jù) |
CATableViewCell 屬性(點(diǎn)擊查看方法介紹)
屬性 | 說(shuō)明 |
ContentView | 內(nèi)容視圖 |
BackgroundView | 背景視圖 |
ReuseIdentifier | 重用標(biāo)識(shí)符 |
Section | section |
Row | cell |
ControlStateEffect | 控制狀態(tài) |
AllowsSelected | 允許選擇 |
CATableViewCell 方法(點(diǎn)擊查看方法介紹)
方法 | 說(shuō)明 |
create | 創(chuàng)建,默認(rèn)Frame為(0,0,0,0) |
initWithReuseIdentifier | 重用標(biāo)識(shí)符初始化 |
CATableViewDelegate 方法(點(diǎn)擊查看方法介紹)
方法 | 說(shuō)明 |
tableViewDidSelectRowAtIndexPath | 選中cell時(shí)調(diào)用 |
tableViewDidDeselectRowAtIndexPath | 取消選擇cell時(shí)調(diào)用 |
CATableViewDataSource 方法(點(diǎn)擊查看方法介紹)
方法 | 說(shuō)明 |
tableCellAtIndex | 獲取指定cell |
tableViewHeightForRowAtIndexPath | 獲取指定的cell高度 |
numberOfRowsInSection | 獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù) |
numberOfSections | 獲取section個(gè)數(shù) |
tableViewSectionViewForHeaderInSection | 在tableView中通過(guò)索引獲取頭部Section |
tableViewHeightForHeaderInSection | 在tableView中通過(guò)索引獲取頭部Section高度 |
tableViewSectionViewForFooterInSection | 在tableView中通過(guò)索引獲取尾部Section |
tableViewHeightForFooterInSection | 在tableView中通過(guò)索引獲取尾部Section高度 |
tableViewWillDisplayCellAtIndex | 回調(diào)當(dāng)前將要顯示的tableView |
我們本節(jié)也使用CATableView來(lái)實(shí)現(xiàn)一個(gè)簡(jiǎn)單的表單視圖,首先我們需要新建一個(gè)Class,命名為:MyTableViewCell并繼承CATableViewCell。代碼示例如下:
文件CATableViewCell.h
#ifndef _My_TableViewCell_h_
#define _My_TableViewCell_h_
#include <iostream>
#include "CrossApp.h"
USING_NS_CC;
class MyTableViewCell:public CATableViewCell
{
public:
MyTableViewCell();
virtual ~MyTableViewCell();
//創(chuàng)建MyTableViewCell
static MyTableViewCell* create(const std::string& identifier, const DRect& _rect = DRectZero);
public:
//初始化
void initWithCell();
//按鈕的回調(diào)函數(shù)
void cellBtnCallback(CAControl* btn, DPoint point);
protected:
//正常狀態(tài)下調(diào)用
virtual void normalTableViewCell();
//高亮狀態(tài)下調(diào)用
virtual void highlightedTableViewCell();
//選擇狀態(tài)下調(diào)用
virtual void selectedTableViewCell();
//禁用狀態(tài)下調(diào)用
virtual void disabledTableViewCell();
//恢復(fù)狀態(tài)下調(diào)用
virtual void recoveryTableViewCell();
};
#endif
文件CATableViewCell.cpp
#include "MyTableViewCell.h"
MyTableViewCell::MyTableViewCell()
{
}
MyTableViewCell::~MyTableViewCell()
{
}
MyTableViewCell* MyTableViewCell::create(const std::string& identifier, const DRect& _rect)
{
//創(chuàng)建
MyTableViewCell* tableViewCell = new MyTableViewCell();
if(tableViewCell&&tableViewCell->initWithReuseIdentifier(identifier))
{
tableViewCell->setFrame(_rect);
tableViewCell->autorelease();
return tableViewCell;
}
CC_SAFE_DELETE(tableViewCell);
return NULL;
}
void MyTableViewCell::initWithCell()
{
//Cell的大小
DSize m_size = this->getFrame().size;
//創(chuàng)建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));
//設(shè)置tag
cellText->setTag(100);
//設(shè)置字體大小
cellText->setFontSize(_px(30));
//設(shè)置中心對(duì)齊
cellText->setTextAlignment(CATextAlignmentCenter);
cellText->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
//添加到當(dāng)前cell
this->addSubview(cellText);
//創(chuàng)建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);
//設(shè)置tag
btnOnCell->setTag(102);
//設(shè)置顯示文本
btnOnCell->setTitleForState(CAControlStateAll, "Touch");
//添加回調(diào)監(jiān)聽
btnOnCell->addTarget(this, CAControl_selector(MyTableViewCell::cellBtnCallback), CAControlEventTouchUpInSide);
//添加到cell
this->addSubview(btnOnCell);
}
void MyTableViewCell::cellBtnCallback(CAControl* btn, DPoint point)
{
//按鈕被點(diǎn)擊時(shí)打印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));
}
我們創(chuàng)建了cell之后,就在FirstViewController實(shí)現(xiàn)CATableViewDelegate和CATableViewDataSource這兩個(gè)代理,那么FirstViewController.h的內(nèi)容如下:
#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時(shí)觸發(fā)
virtual void tableViewDidSelectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);
//取消選中cell時(shí)觸發(fā)
virtual void tableViewDidDeselectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);
//獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù)
virtual unsigned int numberOfRowsInSection(CATableView *table, unsigned int section);
//獲取tableview包含的section個(gè)數(shù)
virtual unsigned int numberOfSections(CATableView *table);
//獲得指定cell
virtual CATableViewCell* tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row);
//設(shè)置section的頭部
virtual CAView* tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section);
//設(shè)置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__) */
然后我們?cè)贔irstViewController.cpp中實(shí)現(xiàn)表格視圖如下:
#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 = cellSize;
//根據(jù)標(biāo)識(shí)獲得cell
MyTableViewCell* cell = dynamic_cast<MyTableViewCell*>(table->dequeueReusableCellWithIdentifier("CrossApp"));
//如果沒(méi)有找到cell
if (cell == NULL)
{
//創(chuàng)建一個(gè)
cell = MyTableViewCell::create("CrossApp", DRect(0, 0, _size.width, _size.height));
//調(diào)用cell的初始化
cell->initWithCell();
}
//如果是section為1的情況
if (section == 1)
{
//根據(jù)tag獲得CAButton
CAButton* cellBtn = (CAButton*)cell->getSubviewByTag(102);
//隱藏按鈕
cellBtn->setVisible(false);
}
else
{
//根據(jù)tag獲得CAButton
CAButton* cellBtn = (CAButton*)cell->getSubviewByTag(102);
//顯示按鈕
cellBtn->setVisible(true);
}
string order = crossapp_format_string("cell-%d",row);
//根據(jù)tag獲得CALabel
CALabel* cellText = (CALabel*)cell->getSubviewByTag(100);
//設(shè)置文本顯示
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);
//創(chuàng)建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數(shù),從0計(jì)算。10表示0-9
return 10;
}
unsigned int FirstViewController::numberOfSections(CATableView *table)
{
//表格數(shù),從0開始計(jì)算。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;
}
這樣我們就構(gòu)建了一個(gè)表格視圖,大家可以自己嘗試這用CATableVIew去實(shí)現(xiàn)一個(gè)微信的通信錄列表。
CATableView 屬性說(shuō)明
類型:CATableViewDataSource*
解釋:添加數(shù)據(jù)代理。set/get{}。
類型:CATableViewDelegate*
解釋:添加交互代理。set/get{}。
類型:CAView*
解釋:添加頭部視圖。set/get{}。
類型:CAView*
解釋:添加尾部視圖。set/get{}。
類型:CAColor4B
解釋:設(shè)置cell分割線的顏色。set/get{}。
類型:unsigned int
解釋:設(shè)置頭部視圖的高度。set/get{}。
類型:unsigned int
解釋:設(shè)置尾部視圖的高度。set/get{}。
類型:unsigned int
解釋:設(shè)置cell分割線的高度。set/get{}。
類型:bool
解釋:是否開啟cell選擇。is{}。
類型:bool
解釋:是否可以多選cell。is{}。
類型:bool
解釋:設(shè)置cell頂部的標(biāo)題。is/set{}。
類型:bool
解釋:設(shè)置cell底部的標(biāo)題。is/set{}。
CATableView 方法說(shuō)明
virtual void setAllowsSelection(bool var);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
bool | var | 是否允許選擇 |
解釋:是否開啟cell選擇
virtual void setAllowsMultipleSelection(bool var);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
bool | var | 是否允許多個(gè)選擇 |
解釋:是否可以多選cell
void setSelectRowAtIndexPath(unsigned int section, unsigned int row);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:設(shè)置選中cell時(shí)調(diào)用
void setUnSelectRowAtIndexPath(unsigned int section, unsigned int row);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:設(shè)置取消選中cell時(shí)調(diào)用
virtual void setShowsScrollIndicators(bool var);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
bool | var | 是否設(shè)置顯示滾動(dòng)條 |
解釋:設(shè)置顯示滾動(dòng)條
unsigned int getNumberOfSections();
返回值:unsigned int
參數(shù):
解釋:獲取tableview包含的section個(gè)數(shù)
unsigned int getNumberOfRowsInSection(unsigned int section);
返回值:unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù)
float getSectionHeightInSection(unsigned int section);
返回值:float
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:通過(guò)索引獲取section高度
float getSectionHeaderHeightInSection(unsigned int section);
返回值:float
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:通過(guò)section索引獲取section頂部的高度
float getSectionFooterHeightInSection(unsigned int section);
返回值:float
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:通過(guò)section索引獲取section底部的高度
float getRowHeightInSectionInRow(unsigned int section, unsigned int row);
返回值:float
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:通過(guò)索引cell高度獲取section和cell
static CATableView* createWithFrame(const DRect& rect);
返回值:static CATableView*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
DRect | rect | 區(qū)域大小 |
解釋:創(chuàng)建,并指定其Frame,默認(rèn)Frame為(0,0,0,0)
static CATableView* createWithCenter(const DRect& rect);
返回值:static CATableView*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
DRect | rect | 中心點(diǎn)的位置及大小 |
解釋:創(chuàng)建,并指定其Center,默認(rèn)Center為(0,0,0,0)
返回值:virtual void
參數(shù):
解釋:初始化
返回值:void
參數(shù):
解釋:重載數(shù)據(jù)
CATableViewCell* dequeueReusableCellWithIdentifier(const char* reuseIdentifier);
返回值:CATableViewCell*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
const char* | reuseIdentifier | 重用標(biāo)識(shí)符 |
解釋:可以重用單元標(biāo)示符
CATableViewCell* cellForRowAtIndexPath(unsigned int section, unsigned int row);
返回值:CATableViewCell*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:通過(guò)索引cell獲取Index路徑
virtual void switchPCMode(bool var);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
bool | var | 開關(guān) |
解釋:開關(guān)PC模式
virtual bool ccTouchBegan(CATouch *pTouch, CAEvent *pEvent);
返回值:virtual bool
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 觸摸傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:觸摸事件開始時(shí)的回調(diào)函數(shù)
virtual void ccTouchMoved(CATouch *pTouch, CAEvent *pEvent);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 觸摸傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:觸摸事件中觸點(diǎn)移動(dòng)時(shí)的回調(diào)函數(shù)
virtual void ccTouchEnded(CATouch *pTouch, CAEvent *pEvent);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 觸摸傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:觸摸事件結(jié)束時(shí)的回調(diào)函數(shù)
virtual void ccTouchCancelled(CATouch *pTouch, CAEvent *pEvent);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 觸摸傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:觸摸非正常結(jié)束時(shí)的回調(diào)函數(shù)。(例如:電話或鎖屏)
virtual void mouseMoved(CATouch* pTouch, CAEvent* pEvent);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:鼠標(biāo)移動(dòng)
virtual void mouseMovedOutSide(CATouch* pTouch, CAEvent* pEvent);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATouch* | pTouch | 傳遞對(duì)象 |
CAEvent* | pEvent | 此參數(shù)待定 |
解釋:鼠標(biāo)移出
CATableViewCell 屬性介紹
類型:CAView*
解釋:內(nèi)容視圖。get{}。
類型:CAView*
解釋:背景視圖。set/get{}。
類型:std::string
解釋:重用標(biāo)識(shí)符。set/get{}。
類型:unsigned int
解釋:section。get{}。
類型:unsigned int
解釋:cell。get{}。
類型:bool
解釋:控制狀態(tài)。is/set{}。
類型:bool
解釋:允許選擇。is/set{}。
CATableViewCell 方法介紹
static CATableViewCell* create(const std::string& reuseIdentifier);
返回值:static CATableViewCell*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
std::string | reuseIdentifier | 重用標(biāo)識(shí)符 |
解釋:創(chuàng)建,默認(rèn)Frame為(0,0,0,0)
virtual bool initWithReuseIdentifier(const std::string& reuseIdentifier);
返回值:virtual bool
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
std::string | reuseIdentifier | 重用標(biāo)識(shí)符 |
解釋:重用標(biāo)識(shí)符初始化
CATableViewDelegate 方法說(shuō)明
virtual void tableViewDidSelectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:選中cell時(shí)調(diào)用
virtual void tableViewDidDeselectRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:取消選擇cell時(shí)調(diào)用
CATableViewDataSource 方法說(shuō)明
virtual CATableViewCell* tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row);
返回值:virtual CATableViewCell*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView | table | 當(dāng)前tableView |
DSize | cellSize | cell大小 |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:獲取指定cell
virtual unsigned int tableViewHeightForRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:獲取指定的cell高度
virtual unsigned int numberOfRowsInSection(CATableView* table, unsigned int section);
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
解釋:獲取對(duì)應(yīng)的section所包含的cell個(gè)數(shù)
virtual unsigned int numberOfSections(CATableView* table);
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
解釋:獲取section個(gè)數(shù)
virtual CAView* tableViewSectionViewForHeaderInSection(CATableView* table, const DSize& viewSize, unsigned int section);
返回值:virtual CAView*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
const DSize& | viewSize | 視圖大小 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:在tableView中通過(guò)索引獲取頭部Section
virtual unsigned int tableViewHeightForHeaderInSection(CATableView* table, unsigned int section);
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
解釋:在tableView中通過(guò)索引獲取頭部Section高度
virtual CAView* tableViewSectionViewForFooterInSection(CATableView* table, const DSize& viewSize, unsigned int section);
返回值:virtual CAView*
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
const DSize& | viewSize | 視圖大小 |
unsigned int | section | cell所屬的區(qū)域 |
解釋:在tableView中通過(guò)索引獲取尾部Section
virtual unsigned int tableViewHeightForFooterInSection(CATableView* table, unsigned int section);
返回值:virtual unsigned int
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
unsigned int | section | cell所屬的區(qū)域 |
解釋:在tableView中通過(guò)索引獲取尾部Section高度
virtual void tableViewWillDisplayCellAtIndex(CATableView* table, CATableViewCell* cell, unsigned int section, unsigned int row);
返回值:virtual void
參數(shù):
類型 | 參數(shù)名 | 說(shuō)明 |
CATableView* | table | 當(dāng)前tableView |
CATableViewCell* | cell | cell |
unsigned int | section | cell所屬的區(qū)域 |
unsigned int | row | cell所在行數(shù) |
解釋:回調(diào)當(dāng)前將要顯示的tableView
更多建議: