0
votes

I give in. I must be missing something simple and primary here!

Question

  • Why do you pass an identifier to UITableView.registerClass()?
  • What is identifier used for?
  • What breaks when you toss in garbage for the identifier?

Source of Question

Ref: func registerClass(_ cellClass: AnyClass?, forCellReuseIdentifier identifier: String)

Example: tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell");

Reference

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/registerClass:forCellReuseIdentifier

enter image description here

1

1 Answers

1
votes

You pass in an identifier to later get a UITableViewCell via that same identifier. If you pass in garbage you have to pass in the same garbage to access it.

Normally in your cellForRowAtIndexPath you write something like

[tableView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

The identifier you use there has to correspond with the identifier you previously registered.

Why do you pass an identifier to UITableView.registerClass()?

To be able to get the a cell with that identifier later on

What is identifier used for?

Same as above

What breaks when you toss in garbage for the identifier?

Nothing, you either have to access the cell via the same garbage later on or you cannot get it out if you pass in something random or stuff like that.