示例#1
0
void CATableView::setSelectRowAtIndexPath(unsigned int section, unsigned int row)
{
    CC_RETURN_IF(section >= m_nSections);
    CC_RETURN_IF(row >= m_nRowsInSections[section]);
    
    if (!m_pSelectedTableCells.empty() && m_bAllowsMultipleSelection == false)
    {
        std::set<CAIndexPath2E>::iterator itr;
        for (itr=m_pSelectedTableCells.begin(); itr!=m_pSelectedTableCells.end(); itr++)
        {
            if (CATableViewCell* cell = m_pUsedTableCells[(*itr)])
            {
                cell->setControlState(CAControlStateNormal);
            }
        }
        m_pSelectedTableCells.clear();
    }
    
    CAIndexPath2E indexPath = CAIndexPath2E(section, row);
    if (CATableViewCell* cell = m_pUsedTableCells[indexPath])
    {
        cell->setControlStateSelected();
    }
    
    m_pSelectedTableCells.insert(indexPath);
}
示例#2
0
void CATableView::setUnSelectRowAtIndexPath(unsigned int section, unsigned int row)
{
    CC_RETURN_IF(section >= m_rSectionRects.size());
    
    CAIndexPath2E indexPath = CAIndexPath2E(section, row);
    CC_RETURN_IF(m_pSelectedTableCells.find(indexPath) == m_pSelectedTableCells.end());
    if (CATableViewCell* cell = m_pUsedTableCells.at(indexPath))
    {
        cell->setControlStateNormal();
    }
    m_pSelectedTableCells.erase(indexPath);
}
示例#3
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);
        }
    }
}
示例#4
0
CATableViewCell* CATableView::cellForRowAtIndexPath(unsigned int section, unsigned int row)
{
    return m_pUsedTableCells[CAIndexPath2E(section, row)];
}
示例#5
0
void CATableView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
    CC_RETURN_IF(m_vTouches.contains(pTouch) == false);
    CAScrollView::ccTouchEnded(pTouch, pEvent);
    
    if (m_pHighlightedTableCells)
    {
        m_pContainer->stopAllActions();
        
        CAIndexPath2E deselectedIndexPath = CAIndexPath2EZero;
        CAIndexPath2E selectedIndexPath = CAIndexPath2E(m_pHighlightedTableCells->getSection(), m_pHighlightedTableCells->getRow());
        m_pHighlightedTableCells = NULL;
        
        if (m_pSelectedTableCells.count(selectedIndexPath) > 0 && m_bAllowsMultipleSelection)
        {
            deselectedIndexPath = selectedIndexPath;
            selectedIndexPath = CAIndexPath2EZero;
            m_pSelectedTableCells.erase(deselectedIndexPath);
        }
        else
        {
            if (!m_pSelectedTableCells.empty() && m_bAllowsMultipleSelection == false)
            {
                deselectedIndexPath = *m_pSelectedTableCells.begin();
                m_pSelectedTableCells.clear();
                
            }
            m_pSelectedTableCells.insert(selectedIndexPath);
            
        }

        if (deselectedIndexPath != CAIndexPath2EZero)
        {
            if (CATableViewCell* cell = m_pUsedTableCells[deselectedIndexPath])
            {
                cell->setControlStateNormal();
            }
            if (m_pTableViewDelegate)
            {
                m_pTableViewDelegate->tableViewDidDeselectRowAtIndexPath(this,
                                                                         deselectedIndexPath.section,
                                                                         deselectedIndexPath.row);
            }
        }
        
        if (selectedIndexPath != CAIndexPath2EZero)
        {
            if (CATableViewCell* cell = m_pUsedTableCells[selectedIndexPath])
            {
                cell->setControlStateSelected();
            }
            if (m_pTableViewDelegate)
            {
                m_pTableViewDelegate->tableViewDidSelectRowAtIndexPath(this,
                                                                       selectedIndexPath.section,

																	   selectedIndexPath.row);
            }
        }
    }
    
}
示例#6
0
void CATableView::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
    CAScrollView::ccTouchEnded(pTouch, pEvent);
    
    if (m_pHighlightedTableCells)
    {
        m_pContainer->stopAllActions();
        
        CAIndexPath2E deselectedIndexPath = CAIndexPath2EZero;
        CAIndexPath2E selectedIndexPath = CAIndexPath2E(m_pHighlightedTableCells->getSection(), m_pHighlightedTableCells->getRow());
        m_pHighlightedTableCells = NULL;
        
        if (m_pSelectedTableCells.count(selectedIndexPath) > 0 && m_bAllowsMultipleSelection)
        {
            deselectedIndexPath = selectedIndexPath;
            selectedIndexPath = CAIndexPath2EZero;
            m_pSelectedTableCells.erase(deselectedIndexPath);
        }
        else
        {
            if (!m_pSelectedTableCells.empty() && m_bAllowsMultipleSelection == false)
            {
                deselectedIndexPath = *m_pSelectedTableCells.begin();
                m_pSelectedTableCells.clear();
                
            }
            m_pSelectedTableCells.insert(selectedIndexPath);
            
        }

        if (deselectedIndexPath != CAIndexPath2EZero)
        {
            if (CATableViewCell* cell = m_pUsedTableCells[deselectedIndexPath])
            {
                cell->setControlStateNormal();
            }
            if (m_pTableViewDelegate)
            {
                m_pTableViewDelegate->tableViewDidDeselectRowAtIndexPath(this,
                                                                         deselectedIndexPath.section,
                                                                         deselectedIndexPath.row);
            }
        }
        
        if (selectedIndexPath != CAIndexPath2EZero)
        {
            if (CATableViewCell* cell = m_pUsedTableCells[selectedIndexPath])
            {
                cell->setControlStateSelected();
            }
            if (m_pTableViewDelegate)
            {
                m_pTableViewDelegate->tableViewDidSelectRowAtIndexPath(this,
                                                                       selectedIndexPath.section,
                                                                       selectedIndexPath.row);
            }
        }
    }
    
    if (m_pTableViewDelegate && m_nTablePullViewHeight > 0)
    {
        CCPoint point  = m_pContainer->getFrameOrigin();
        
        if (m_pTablePullDownView
            && point.y
            >= m_nTablePullViewHeight)
        {
            m_bToUpdate     =   CATableViewToUpdatePullDown;
            
            point.y         =   m_nTablePullViewHeight;
            
            this->setContentOffset(ccpMult(point, -1), true);
        }
        
        if (m_pTablePullUpView
            && point.y
            <= this->getBounds().size.height
                - m_pContainer->getFrame().size.height
                - m_nTablePullViewHeight)
        {
            m_bToUpdate     =   CATableViewToUpdatePullUp;
            
            point.y         =   this->getBounds().size.height
                                - m_pContainer->getFrame().size.height
                                - m_nTablePullViewHeight;
            
            this->setContentOffset(ccpMult(point, -1), true);
        }
    }
}