UITableVIew的性能优化-重用原理
UITableVIew的性能優(yōu)化:使用方法創(chuàng)建cell時,先優(yōu)先從緩存池中找cell,找不到再創(chuàng)建新的cell,并且要綁定Identifer標(biāo)示。
代碼:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//? ? 定義一個靜態(tài)的標(biāo)識(只會初始化一次,內(nèi)存分配一次)
? ? static NSString *ID = @"c1";
//? ? 優(yōu)先從緩存池中去找cell
? ? UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
//? ? 緩存池中找不到就創(chuàng)建一個新的cell,一定要綁定標(biāo)示
? ? if (cell == nil) {
? ? ? ? cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
? ? }
}
轉(zhuǎn)載于:https://www.cnblogs.com/yuyu-2012/p/4646789.html
總結(jié)
以上是生活随笔為你收集整理的UITableVIew的性能优化-重用原理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Protocol
- 下一篇: 17.观察者模式(Observer Pa