简体   繁体   中英

What is “dequeue cell”

您能帮我解释一下有关“出队单元格”的详细信息,以及dequeueReusableCellWithIdentifier:forIndexPath方法中的“正确调整大小”是什么吗?

Dequeue cell :- returns a reusable table-view cell object for the specified reuse identifier and adds it to the table.

Creating Table View Cells

  • registerNib:forCellReuseIdentifier:
  • registerClass:forCellReuseIdentifier:
  • dequeueReusableCellWithIdentifier:forIndexPath:
  • dequeueReusableCellWithIdentifier:

Refer apple document for more description on these delegate methods, https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/dequeueReusableCellWithIdentifier:forIndexPath :

This is the way you add the dequeue cell method for the table view in the method cellforrowatindexpath .

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.text = [NSString stringWithFormat:@"cell%i%i", indexPath.section, indexPath.row];
    }    
    return cell;
}

This is the resize properly method and what it does.

- (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0); // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

And here is a tutorial for the same table view dequeue cell in swift https://thatthinginswift.com/table-data-sources/

http://shrikar.com/uitableview-and-uitableviewcell-customization-in-swift/

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