简体   繁体   中英

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. Does anybody know how it is possible?

According to Apple's documentation :

Return Value

An object representing a cell of the table or nil if the cell is not visible or indexPath is out of range.

So if that cell is not currently visible then it will return 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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