0

Im trying to programmatically switch from a UITableView to a SKView (Can't use the storyboard to place buttons on a TableView).

This is the code a have to switch views:

ViewController.swift :

    func game() {
    let game = GameViewController()
    present(game, animated: true, completion: nil)

}

GameViewController.swift :

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .aspectFill

        skView.presentScene(scene)
    }
}

override var shouldAutorotate : Bool {
    return true
}

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
    if UIDevice.current.userInterfaceIdiom == .phone {
        return .allButUpsideDown
    } else {
        return .all
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override var prefersStatusBarHidden : Bool {
    return true
   }
}

It is giving me the error:

Could not cast value of type 'UIView' (0x1102beb40) to 'SKView' (0x10f0814c8).

I know it is a code issue but I don't know what to fix.

CHANGING THE CLASS TO SKVIEW DOESN'T WORK!!

1 Answers1

0

i had the same problem before. Go to your storyboard and in your identity inspector, set custom class to SCNView

//set custom class to SCNView