示例#1
0
void CATableView::loadTableCell()
{
    CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
    for (unsigned int i=0; i<(unsigned int)m_rTableCellRectss.size(); i++)
    {
        for (unsigned int j=0; j<(unsigned int)m_rTableCellRectss.at(i).size(); j++)
        {
            CAIndexPath2E indexPath = CAIndexPath2E(i, j);
            CC_CONTINUE_IF(m_pUsedTableCells.count(indexPath) && m_pUsedTableCells[indexPath]);
            CCRect cellRect = m_rTableCellRectss[i][j];
            CC_CONTINUE_IF(!rect.intersectsRect(cellRect));
            CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, m_rTableCellRectss[i][j].size, i, j);
            CC_CONTINUE_IF(cell == NULL);
            cell->m_nSection = i;
            cell->m_nRow = j;
            cell->updateDisplayedAlpha(this->getAlpha());
            m_pContainer->addSubview(cell);
            cell->setFrame(m_rTableCellRectss[i][j]);
            m_pUsedTableCells[indexPath] = cell;
            if (m_pSelectedTableCells.count(indexPath))
            {
                cell->setControlStateSelected();
            }
            
            CAView* view = this->dequeueReusableLine();
            CCRect lineRect = m_rLineRectss[i][j];
            if (view == NULL)
            {
                view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
            }
            m_pUsedLines[indexPath] = view;
            this->insertSubview(view, 1);
            view->setFrame(lineRect);
        }
    }
}
示例#2
0
void CATableView::reloadData()
{
    this->reloadViewSizeData();

    this->removeAllSubviews();
    
    float width = this->getBounds().size.width;
    int y = 0;
    
    if (m_pTablePullDownView)
    {
        m_pTablePullDownView->setFrame(CCRect(0, -(float)m_nTablePullViewHeight, width, m_nTablePullViewHeight));
        this->addSubview(m_pTablePullDownView);
    }
    
    if (m_pTablePullUpView)
    {
        m_pTablePullUpView->setFrame(CCRect(0, this->getBounds().size.height, width, m_nTablePullViewHeight));
        this->addSubview(m_pTablePullUpView);
    }
    
    if (m_pTableHeaderView)
    {
        m_pTableHeaderView->setFrame(CCRect(0, y, width, m_nTableHeaderHeight));
        this->addSubview(m_pTableHeaderView);
        y += m_nTableHeaderHeight;
    }
    
    
    unsigned int sectionCount = m_pTableViewDataSource->numberOfSections(this);
    
    m_rTableCellRectss.resize(sectionCount);
    for (unsigned int i=0; i<sectionCount; i++)
    {
        CAView* sectionHeaderView = m_pTableViewDataSource->tableViewSectionViewForHeaderInSection(this, i);
        if (sectionHeaderView)
        {
            sectionHeaderView->setFrame(CCRect(0, y, width, m_nSectionHeaderHeights.at(i)));
            this->addSubview(sectionHeaderView);
        }
         y += m_nSectionHeaderHeights[i];
        
        m_rTableCellRectss[i].resize(m_nRowHeightss[i].size());
        for (unsigned int j=0; j<m_rTableCellRectss[i].size(); j++)
        {
            m_rTableCellRectss[i][j] = CCRect(0, y, width, m_nRowHeightss[i][j]);
            
            CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, i, j);
            cell->setFrame(m_rTableCellRectss[i][j]);
            this->addSubview(cell);
            cell->setSection(i);
            cell->setRow(j);
            m_pTableCells.push_back(cell);
            
             y += m_nRowHeightss[i][j];
            
            if (j < m_nRowHeightss.at(i).size() - 1)
            {
                CAView* view = CAView::createWithFrame(CCRect(0, y, width, 1), m_separatorColor);
                this->addSubview(view);
                y += 1;
            }
        }
        
        CAView* sectionFooterView = m_pTableViewDataSource->tableViewSectionViewForFooterInSection(this, i);
        if (sectionFooterView)
        {
            sectionFooterView->setFrame(CCRect(0, y, width, m_nSectionFooterHeights.at(i)));
            this->addSubview(sectionFooterView);
        }
        y += m_nSectionFooterHeights.at(i);
    }
    
    if (m_pTableFooterView)
    {
        m_pTableFooterView->setFrame(CCRect(0, y, width, m_nTableFooterHeight));
        this->addSubview(m_pTableFooterView);
        y += m_nTableFooterHeight;
    }
    
}