I have problem that was asked here UITableViewCell outside of UITableView but has no correct answer except ‘it’s not a good idea’.
I want to load cell’s contentView outside tableView (example situation — when user’s click cell he is navigated to new table view where that cell acts as part of headerView).
Resolution proposed in topic I’ve provided link was:
What I have done is loaded the cell from its nib, set it up, and then
added the contentView of the cell to my new pushed view. This achieves
much of the same effect.
MyUITableViewCell(style:, reuseIdentifier: nil)
MyUITableViewCell(nib: nib, bundle: nil)
To straight up load a cell from a nib without using the table view, you need to load it from the main bundle.
CustomClass *cell = (CustomClass *)[[[NSBundle mainBundle] loadNibNamed:@"nibName" owner:self options:nil] firstObject]
let cell = NSBundle.mainBundle().loadNibNamed("nibName", owner: self, options: nil).first as! CustomClass
Once you load it you still need to do your setup and set the frame of the cell and add it to superview. You can then use this view just like any other view.
The reason why the init methods don't work is because the view never gets any of its IBOutlets initialized from the nib, so all your cell's properties for the outlets are nil.