Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - registerClass with Swift

Is anyone else having an issue using the tableView.registerClass method with Swift?

It no longer comes in code completion for me (nor can I use it if manually typed) but it is still in the headers...

Code Completion

UITableView headers

like image 605
Stuart Breckenridge Avatar asked Aug 17 '14 08:08

Stuart Breckenridge


People also ask

How do I register a custom cell in Swift?

Go to the XIB file and make sure the cell is selected to set some properties in the Attributes Inspector. First add an identifier "HabitCell" for cell reuse. Next select an Accessory, choose the option "Disclosure indicator", this is the arrow that you see in the right side of the cell.

What is UITableView in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+

What is register in Swift?

If you want to use register() with a Swift class, you provide a table view cell class as its first parameter. This is useful if your cell is defined entirely in code. As an example, this uses the default UITableViewCell class: tableView. register(UITableViewCell.

Is it possible to add UITableView within a UITableViewCell?

yes it is possible, I added the UITableVIew within the UITableView cell .. :) no need to add tableview cell in xib file - just subclass the UITableviewCell and use the code below, a cell will be created programatically.


1 Answers

It works for me perfectly.

self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 

Exactly as I have it above.

like image 171
Woodstock Avatar answered Oct 01 '22 19:10

Woodstock