Exemple #1
0
void CAListView::loadCell()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.origin.x -= rect.size.width * 0.1f;
    rect.size.width *= 1.2f;
    rect.size.height *= 1.2f;
    
	std::map<unsigned int, CAListViewCell*>::iterator itr;
	for (itr = m_mpUsedListCells.begin(); itr != m_mpUsedListCells.end(); itr++)
	{
		CC_CONTINUE_IF(itr->second != NULL);

		unsigned int index = itr->first;
		DRect cellRect = m_rIndexRects[index];
		CC_CONTINUE_IF(!rect.intersectsRect(cellRect));

		CAListViewCell* cell = m_pListViewDataSource->listViewCellAtIndex(this, cellRect.size, index);
		if (cell)
		{
            cell->m_nIndex = index;
            cell->updateDisplayedAlpha(this->getAlpha());
			addSubview(cell);
			cell->setFrame(cellRect);
            m_mpUsedListCells[index] = cell;
            m_vpUsedListCells.pushBack(cell);
		}

		if (m_pSelectedListCells.count(index))
		{
			cell->setControlState(CAControlStateSelected);
		}
        
        if (m_pListViewDataSource)
        {
            m_pListViewDataSource->listViewWillDisplayCellAtIndex(this, cell, index);
        }
        
        CAView* view = this->dequeueReusableLine();
        DRect lineRect = m_rLineRects[index];
        if (view == NULL)
        {
            view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
        }
        m_pUsedLines[index] = view;
        this->insertSubview(view, 1);
		view->setFrame(lineRect);
	}
}
Exemple #2
0
void CAListView::reloadData()
{
	if (m_pListViewDataSource == NULL)
		return;
    
    this->reloadViewSizeData();
    
    this->removeAllSubviews();
    
    m_pUsedLines.clear();
	m_pUsedListCells.clear();
	m_pFreedListCells.clear();
    m_pSelectedListCells.clear();
	
	CCRect winRect = this->getBounds();
    winRect.origin = this->getContentOffset();
    
	if (m_nListHeaderHeight > 0)
	{
		if (m_pListHeaderView)
		{
			m_pListHeaderView->setFrame(m_rHeaderRect);
			addSubview(m_pListHeaderView);
		}
	}

	unsigned int cellCount = m_pListViewDataSource->numberOfIndex(this);
	for (unsigned i = 0; i < cellCount; i++)
	{
		if (m_nIndexs > 0)
		{
			std::pair<std::map<unsigned int, CAListViewCell*>::iterator, bool> itrResult =
				m_pUsedListCells.insert(std::make_pair(i, (CAListViewCell*)NULL));

			CC_CONTINUE_IF(!winRect.intersectsRect(m_rIndexRects[i]));

			CAListViewCell* pCellView = m_pListViewDataSource->listViewCellAtIndex(this, m_rIndexRects[i].size, i);
			if (pCellView)
			{
				pCellView->m_nIndex = i;
				pCellView->setFrame(m_rIndexRects[i]);
				addSubview(pCellView);
				itrResult.first->second = pCellView;
			}
		}
        
		if (m_nSeparatorViewHeight > 0)
		{
			CAView* view = CAView::createWithFrame(m_rLineRects[i], m_obSeparatorColor);
			addSubview(view);
            m_pUsedLines[i] = view;
		}
	}

	if (m_nListFooterHeight > 0)
	{
		if (m_pListFooterView)
		{
			m_pListFooterView->setFrame(m_rFooterRect);
			addSubview(m_pListFooterView);
		}
	}
    this->layoutPullToRefreshView();
    this->startDeaccelerateScroll();
}