Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom cell class in UITableView with static cells

I have a UITableView with static cells in a Storyboard. The static cells are of a custom class. I would like to wire up the outlets for the cell but it seems like this is not supported?

Wiring the views onto the ViewController works, but is rather messy (there are lots of cells). A workaround would probably also be to tag the views, but also not ideal. Any other ideas?

enter image description here

like image 217
liliqui Avatar asked Mar 26 '16 07:03

liliqui


People also ask

What are static cells?

Static cell is a crafting material that has a chance to drop when killing an Anglure [20%], Bobot [10%], Scandroid [10%], Voltip [20%] or Lumoth [10%]. It can also be harvested from Electric Fluffalo, which can be hatched from eggs purchasable at Terramart.

How can we use a reusable cell in UITableView?

For performance reasons, a table view's data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView(_:cellForRowAt:) method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse.


1 Answers

You cannot control-drag your UIView to the source file. However, you can link up the other way around.

  1. In Storyboard, select your static cell, and setup the Custom Class.
  2. In your custom class, add all the @IBOutlet as you need.
  3. Go back to Storyboard, select your static cell, and in Inspector, select Show the Connections Inspector (the last tab).
  4. Drag the Outlets there to your UIView(s).

If you use "assistant editor", you will see the circle in front of @IBOutlet is now filled (hooked).

like image 102
John Pang Avatar answered Nov 08 '22 17:11

John Pang