Should I use dequeReusableCellWithIdentifier?

I know this question is dumb. But suddenly stuck in this matter.

When I use dequeReusableCellWithIdentifier , the cells are reused. To be more specific, first the 'n' cell set is reused along with its links

Since the same links are reused, I cannot actually store local variables in cells. I really need to assign them every time in cellForRowAtIndexPath

Suppose I use the UITableviewcell user complex. (I know we need to reduce complexity, but still ...)

Some views must be added to the cell.

The best example I could think of is an image slider.

Thus, the number of images on the image slider depends on the data source. Therefore, I need to add views to cellForRowAtIndexPath. I can’t avoid it.

Since the same cell reference is being reused, I need to add these views every time cellForRowAtIndexPath is called. I think this is a heavy load.

I was thinking about using drawRect method , but it does not work with UITableViewAutomaticDimension

If I do not use dequeReusableCell, I will have separate reference cells, but it will cost memory and performance.

So what is the best solution? Can I use dequeReusableCell and still do not need to rewrite its contents?

1: dequeReusableCell, dequeueReusableCellWithIdentifier - forIndexPath. .

2: , .

, view. cellForRowAtIndexPath dequeueReusableCellWithIdentifier - forIndexPath

, , , , , cellForRowAtIndexPath.

, n . "n" . .

, tableView cellForRowAtIndexPath, .

, .

+4
5

, , :

  • dequeReusableCell: , .
  • cleanCell UITableViewCell, , ( )
  • cellForRowAtIndexPath:
+1

: . cellForRowAtIndexPath , , ( ). , cellForRowAtIndexPath :

cell = [tableView dequeueReusableCellWithIdentifier...forIndexPath...];
cell.modelObject = myModelObject;

.

. , , .

, , 5 , . , , / UIImageView . , / cellForRow. 5 UIImageView , modelObject.rating. - . , :)

UPDATE: , , , . , , 3 . . prepareForReuse, . , , 1 , 2 ( , , , : ) 5, . 3, .

+1

dequeueReusableCellWithIdentifier(_ identifier: String, forIndexPath indexPath: NSIndexPath). , .

, cellForRowAtIndexPath. , .

cellForRowAtIndexPath. . cellForRowAtIndexPath .

, :

var items = [UIImage]()

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("ImageCell", forIndexPath: indexPath)

    let item = items[indexPath.row]
    let recipient = item.recipients.first

    // I have given my UIImageView tag = 101 to easily access it from the view controller.
    // This allows me to avoid defining a custom UITableViewCell subclass for simple cells.
    if let imageView = cell.viewWithTag(101) as? UIImageView {
        imageView.image = item
    }

    return cell
}
0

1) , " " . http://www.theappguruz.com/blog/ios-lazy-loading-images ()

2) viewController NSMutableDictionary, , , "ID" , indexPath.row , , , -cellForRow,

[self.dataDictionary objectForKey: @ "cellID" ];

. -cellForRow , .

if ([self.dataDictionary objectForKey:@"cellID"]) {
  cell.cellImage = [self.dataDictionary objectForKey:@"cellID"];
} else {
  UIImage *img = [uiimage load_image];
  cell.cellImage = img;
  [self.dataDictionary setObject:img forKey:@"cellID"];
}

. , , , .

0

, . , @Eiko.

When you use reusable cells, it must be completely reused. If you intend to change your views based on data, you will either have to use a new identifier or avoid using reusable cells.

But avoiding reusable cells, you get a load. Therefore, you should either use different identifiers for similar cells, or as @FreeNickName - you can use the intermediate configuration and change it as you need.

0
source

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


All Articles