What is a cell id for?

I wonder why I need a cell id in a UITableView ... like this:

static NSString *cellIdentifier = @"Cell";

what is it for? Example?

+3
source share
3 answers

It is used as a key for caching cells, for example:

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

    static NSString * CellIdentifier    = @"MyCell1";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   ...

Then in another table another identifier may be used ...

+3
source

UITableView should be able to smoothly and quickly display fast-changing data, and sometimes cells have additional code to build the cell itself using Core Graphics or the like.

UITableView , "". , apple dequeueReusableCellWithIdentifier. , , .

UITableView . , , , - , . - . CellIdentifier dequeue, , , .

static NSString *CellIdentifier = @"Cell with image";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];

, , :

if(cell == nil) ....

, , CellIdentifier .

Theres Apple : https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html

. :

: http://www.digitalhobbit.com/2009/12/19/a-useful-uitableview-cell-creation-pattern/

+8

, . , , , , , , . , , 10 . - , . , . .

+1

Source: https://habr.com/ru/post/1729968/


All Articles