Search code examples
iosswiftuitableviewskscene

Is it possible to subclass UITableView to a SKNode?


Is there a way to add a UITableView from a custom class to a SKScene? Within the scene, I can add a tableView using the following line:

self.view?.addSubview(myTableView)

but to keep my code a bit cleaner, I wondered if it there's a way to create a custom class containing the tableView, adding it from there to a scene.


Solution

  • One thing to keep in mind while adding UIKit elements to an SKScene is that you must remove it from the view when the scene is uninitialized, otherwise it will remain even as the scene switches.

    But back to your question. I believe that this will solve your answer. Between the question and the answer you should be good to go. Use TableViewController inside SKScene