简体   繁体   中英

Custom UITableViewCell - subclass UITableViewCell with xib vs using tags

In order to implement a custom UITableViewCell, I know of two options:

  • Create a prototype cell in the storyboard view and assign tags to the cell's constituent views
  • Create a subclass of UITableViewCell with an associated xib

Using the tags seems simpler. I see that it has a couple of disadvantages including the inability to re-use the custom cell in more than one scene and potentially a lot of cell specific code in the view controller which could be an issue with a bunch of different cells.

For one or two cells that do not need to be reused in multiple scenes, does anyone know of any other considerations that I should take into account that might lead me to prefer a UITableViewCell subclass?

My recommendation is to use a UITableViewCell subclass with a storyboard prototype cell. Simply link your constituent views to IBOutlet properties as you would with any other class.

If you want to use the same cell in multiple tables then you need to re layout the prototype cell in each tableView, but you can cut and paste. Using tags results in unnecessary code to get references to the UI elements.

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