visibleCells

本文介绍UITableView中可见单元格(cell)的计数方法及如何仅针对这些可见单元格进行绘制,有助于提高应用性能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[ [ tableView visibleCells ] count ]

仅仅是UITableView上可以看到的cell

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

绘制的也仅仅是能看到的cell
``` m_idTopLeftCell.row = -1; if (!m_bAllowDraw || !::IsWindow(GetSafeHwnd())) return; CRect rect; // This would have caused OnSize event - Brian //EnableScrollBars(SB_BOTH, FALSE); GetClientRect(rect); if (rect.left == rect.right || rect.top == rect.bottom) return; if (IsVisibleVScroll()) rect.right += GetSystemMetrics(SM_CXVSCROLL) + GetSystemMetrics(SM_CXBORDER); if (IsVisibleHScroll()) rect.bottom += GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYBORDER); rect.left += GetFixedColumnWidth(); rect.top += GetFixedRowHeight(); if (rect.left >= rect.right || rect.top >= rect.bottom) { EnableScrollBarCtrl(SB_BOTH, FALSE); return; } CRect VisibleRect(GetFixedColumnWidth(), GetFixedRowHeight(), rect.right, rect.bottom); CRect VirtualRect(GetFixedColumnWidth(), GetFixedRowHeight(), GetVirtualWidth(), GetVirtualHeight()); // Removed to fix single row scrollbar problem (Pontus Goffe) // CCellRange visibleCells = GetUnobstructedNonFixedCellRange(); // if (!IsValid(visibleCells)) return; //TRACE(_T("Visible: %d x %d, Virtual %d x %d. H %d, V %d\n"), // VisibleRect.Width(), VisibleRect.Height(), // VirtualRect.Width(), VirtualRect.Height(), // IsVisibleHScroll(), IsVisibleVScroll()); // If vertical scroll bar, horizontal space is reduced if (VisibleRect.Height() < VirtualRect.Height()) VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL); // If horz scroll bar, vert space is reduced if (VisibleRect.Width() < VirtualRect.Width()) VisibleRect.bottom -= ::GetSystemMetrics(SM_CYHSCROLL); // Recheck vertical scroll bar //if (VisibleRect.Height() < VirtualRect.Height()) // VisibleRect.right -= ::GetSystemMetrics(SM_CXVSCROLL); if (VisibleRect.Height() < VirtualRect.Height()) { EnableScrollBars(SB_VERT, TRUE); m_nVScrollMax = VirtualRect.Height() - 1; } else { EnableScrollBars(SB_VERT, FALSE); m_nVScrollMax = 0; } if (VisibleRect.Width() < VirtualRect.Width()) { EnableScrollBars(SB_HORZ, TRUE); m_nHScrollMax = VirtualRect.Width() - 1; } else { EnableScrollBars(SB_HORZ, FALSE); m_nHScrollMax = 0; } ASSERT(m_nVScrollMax < INT_MAX && m_nHScrollMax < INT_MAX); // This should be fine /* Old code - CJM SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_PAGE; si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0; SetScrollInfo(SB_HORZ, &si, FALSE); si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0; SetScrollInfo(SB_VERT, &si, FALSE); SetScrollRange(SB_VERT, 0, m_nVScrollMax, TRUE); SetScrollRange(SB_HORZ, 0, m_nHScrollMax, TRUE); */ // New code - Paul Runstedler SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_PAGE | SIF_RANGE; si.nPage = (m_nHScrollMax>0)? VisibleRect.Width() : 0; si.nMin = 0; si.nMax = m_nHScrollMax; SetScrollInfo(SB_HORZ, &si, TRUE); si.fMask |= SIF_DISABLENOSCROLL; si.nPage = (m_nVScrollMax>0)? VisibleRect.Height() : 0; si.nMin = 0; si.nMax = m_nVScrollMax; SetScrollInfo(SB_VERT, &si, TRUE);```分析这段代码
最新发布
03-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值