简体   繁体   English

如何从UITableView获取单元格

[英]How to get cell from UITableView

Why does this code return a cell? 为什么此代码返回一个单元格?

static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

But when I am trying to get cell with [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] it does not return anything. 但是,当我尝试使用[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]获取单元格时,它不返回任何内容。 Does anybody know how it is possible? 有人知道这怎么可能吗?

According to Apple's documentation : 根据Apple的文档

Return Value 返回值

An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range. 表示表单元格的对象;如果该单元格不可见或indexPath超出范围,则为nil。

So if that cell is not currently visible then it will return nil . 因此,如果该单元格当前不可见,则它将返回nil So, is it visible? 那么,可见吗?

Other than that - check that you are actually creating cells in cellForRowAtIndexPath: as you haven't specifically shown that you are. 除此之外,请检查您是否确实在cellForRowAtIndexPath:创建了单元格cellForRowAtIndexPath:因为您没有明确表明自己是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM