Reference to a TableView Delegate Object within a Scene in Swift 4

Multi tool use
Multi tool use


Reference to a TableView Delegate Object within a Scene in Swift 4



I have a tableview in a SpriteKit scene. Using a tableview delegate method, I like to pass to another scene/ViewController, which cell was selected. There is only a single storyboard as this is entirely a SpriteKit game.


//TableView inside Scene & Delegate Protocol:

protocol gameSelectedDelegate {
func theGameSelected(gameInt: Int)
}

class GamesTableView: UITableView, UITableViewDelegate,UITableViewDataSource {
//Test Data
var items: [String] = ["Player1", "Player2"]
let defaults = UserDefaults.standard
var gamesList = [Game]()
var passedGame: Int?

//instance of delegate
var selectionDelegate: gameSelectedDelegate!`




//GameScene to receive tableview data and delegate for my tableview

class GamePlay: SKScene, gameSelectedDelegate {

var backButton = SKLabelNode(fontNamed: "ArialRoundedMTBold")
var score = SKLabelNode(fontNamed: "ArialRoundedMTBold")
var passedGame = 0 //Not getting passed from LoadGame
var passedGameDelegate:Int? = nil


override func sceneDidLoad() {

let grid = childNode(withName: "grid")
grid?.zPosition = 1
self.backgroundColor = UIColor.black

let sc = GamesTableView.self //How do I get a reference to my tableview?
sc.selectionDelegate = self





Your question isn't very clear. Why did you subclass UITableView? You either want to subclass UIViewController and put a UITableView in it, or you want to subclass UITableViewController. How do the table view and the sprite kit scenes relate?
– Paulw11
Jul 2 at 2:15



UITableView


UIViewController


UITableView


UITableViewController









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ceb3,Xl2RFaban1fOAVBtZ6cM,jm1Wi,hq5GdZtw TaX3JK9R09DZRacQDOgZ7pe0DvSk,TGmjXEvhvow
CVCG3MRH,r,aZih3 4uj8,JCBGm K9NWkN Xed,6nqBkIW20q

Popular posts from this blog

Rothschild family

Cinema of Italy