0

In the table view of DetailTableViewController, I use a prototype cell from the storyboard. But for some cases, the prototype cell is not appropriate, so i defined a custom cell with a nib and a custom cell class for the nib. Then i register the custom nib cell in the DetailTableViewController's method viewDidLoad() with a special cell reuse identifier. Then in the tableView(_:cellForRowAtIndexPath:) , i dequeue the custom nib cell for its correspond circumstances. and in some cases, i dequeue the prototype cell to use.

But i found that if these two kinds of cell coexists in the table view, the prototype cell affects the appearance of the custom nib cell. for example, when i change the background color the of the custom nib cell, it shows the prototype's background color. and i have to click the custom nib cell to reveal its real background color.

If i delete the prototype cell to empty, and only use the custom nib cell, then everything works fine.

Is there something special for the prototype cell? as i know(from this answer), prototype cell is nothing more than a custom nib cell defined in the storyboard. Then why?

Community
  • 1
  • 1
shellhue
  • 569
  • 6
  • 12
  • You can define multiple prototype cells in the storyboard, each with a different layout, custom class and re-use identifier. Then you simply provide the appropriate re-use identifier to `dequeueReusableCellWithIdentifier:` – Paulw11 Sep 29 '15 at 01:11
  • Thanks very much, your way is better. – shellhue Sep 29 '15 at 11:40

1 Answers1

0

Finally, i found that it is not the prototype cell affecting the custom cell. Instead, it is the prototype cell instance which is more than the number needed affecting the custom cell instance. when the table view asks for a cell, i created a prototype cell instance first. and then i check whether it is suitable for the indexPath. if not, i then create a custom cell instance and return it.

That means some prototype cell instances are created, but not used. cell instance is expensive, i think apple uses this unused cells for some performance enhance(i am not sure about this). Therefore, they affect the custom cell instance. After i correct this error, everything works fine. If anybody knows the detail reason, please post here. Really appreciated.

Hope this answer is helpful.

shellhue
  • 569
  • 6
  • 12