注册细胞重用的调用实际上做了什么? [英] What does registering a call for cell reuse actually do?

查看:102
本文介绍了注册细胞重用的调用实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全理解注册一个类进行单元重用的内容。我理解我们如何在单元格上使用重用标识符,我只是不明白在viewDidLoad中调用此方法的内容。看了一堆文档。不点击,在这里n00b。有人可以给我一些关于它的好处的提示吗?

I don't totally understand what registering a class for cell reuse does. I understand how we use reuse identifiers on cells, I just don't understand what calling this method in viewDidLoad does. Looked at a bunch of docs. Not clicking, n00b here. Could someone give me some tips on what it does please?

TableViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    // Register Class for Cell Reuse Identifier
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
}


推荐答案

你有的UITableView 。它有一个数据源,提供它 UITableViewCell s。为了节省内存和处理器周期,它卸载不再在屏幕上的 UITableViewCell ,并将它们放入重用队列。当它加载一个新单元格时,数据源通常会向此重用队列请求 UITableView 中的单元格。如果队列当前为空, UITableView 将使用提供的类构造一个新的 UITableViewCell reuseIdentifier 用于区分此特定单元格类型队列与同一 UITableView 中的另一个单元格类型队列。

You have a UITableView. It has a datasource that provides it UITableViewCells. To save memory and processor cycles, it unloads UITableViewCells that are no longer on screen and puts them into a reuse queue. When it loads a new cell, the datasource will typically ask the UITableView for a cell from this reuse queue. If the queue is currently empty, UITableView will construct a new UITableViewCell using the class provided. The reuseIdentifier is used to distinguish this particular cell type queue from another cell type queue within the same UITableView.

这样的事情:

UITableView :嘿,数据源给我这个indexPath的单元格。

UITableView: "Hey, Datasource! Give me the cell for this indexPath."

Datasource :好吧。那是'foo'类的你有没有使用那些你没有使用过的人?

Datasource: "Alright. That's a 'foo' kind of cell. Got any of those kicking around that you're not using?"

没有注册课程;重新使用从数据源返回的单元格

UITableView :是的,我知道。你走了。

UITableView: "Yes, I do. Here you go."

没有注册课程;没有可用的单元格

UITableView :没有。嘿,我没有注册的课程对于那种单元格。嗯。这里是 nil 而是。

UITableView: "Nope. Hey, I don't have a class registered for that kind of cell. Hmm. Here's nil instead."

已注册的类;重新使用从数据源返回的单元格

UITableView :是的,我知道。你走了。

UITableView: "Yes, I do. Here you go."

已注册的班级;没有可用的单元格

UITableView :没有。但我有一个为该标识符注册的类。这是一个新实例。

UITableView: "Nope. But I have a class registered for that identifier. Here's a new instance."

这篇关于注册细胞重用的调用实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆