Storyboard is very convenient to visually design the cells of tableview and tableview. However, some people may have come from hand-written code controls in the early days, so there are some important points here.
1. registerClass cannot be used
2. You do not need to judge if dequeueReusableCellWithIdentifier forIndexPath returns an empty cell, because it will certainly return a non-empty cell, and the cell after subclass should not write initWithStyle.
3. How can I know how to reuse cells in advance? Rewrite cell prepareForReuse
---------- Split line, followed by a specific explanation ---------------------------
1. registerClass cannot be used
When we use UITableView in storyboard mode, UITableViewCell cannot be registered using registerClass.
Generally, when you use UITableView in ios6, you can use the following method to register the reuse ID in viewDidLoad.
[Self. tableView registerClass: [RecipeBookCell class] forCellReuseIdentifier: @ "RecipeCell"];
This method is for manual use. When you use this registerClass registration, the Dynamic Prototypes drawn in the storyboard will no longer take effect.
- (}
2. You do not need to judge if dequeueReusableCellWithIdentifier forIndexPath returns an empty cell, because it will certainly return a non-empty cell, and the cell after subclass should not write initWithStyle.
Another thing to note is that in the handwriting code method, it usually determines whether the cell returned by tableView dequeueReusableCellWithIdentifier forIndexPath is null. If it is null, alloc and initWithStyle are called. (that is, if registerClass is used before, this judgment is required)
After using the Dynamic Prototypes of storyboard, it will never be called here, because dequeueReusableCellWithIdentifier forIndexPath will never return cells equal to nil to you.
At the same time, this means that initWithStyle will not be called after your UITableViewCell subclass is made, and you should not bother to write code in it.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath * NSString *simpleTableIdentifier = *cell = (cell == cell.nameLabel.text ===
3. How can I know how to reuse cells in advance? Rewrite cell prepareForReuse
The official header file indicates that if the allocated cell is reused (usually scrolling out of the screen), the cell prepareForReuse will be called to notify the cell.
Note that when you override the method here, you must call the parent class method [super prepareForReuse].
Pay special attention to this when using cell as the proxy container for network access. You need to cancel the previous network request here and do not send data to this cell.
- (