Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generic UIViewController subclass
// usage
let pop = PopoverViewController<SomeViewController>()
self.showViewController(pop) // adds pop.view as a subview (stepping over this line reveals that pop.view becomes non-nil)
// -viewDidLoad is not called...
class PopoverViewController<ContentViewControllerType: UIViewController>: UIViewController {
var omitted: Whatever?
// I'm not entirely sure why I need these initializers, considering I have one optional var property...
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
convenience override init() {
self.init(nibName: nil, bundle: nil)
}
// Not called!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.orangeColor()
}
}
@fdematos

This comment has been minimized.

Copy link

fdematos commented Nov 18, 2014

Hi,
I got the same problem.

I am trying to create a class of type MyClass:UIViewController
ViewDidLoad is not called. Same for loadView, it's not called.

Did you understand why ?

@ccwasden

This comment has been minimized.

Copy link

ccwasden commented Dec 5, 2014

I am doing something similar:

class SimpleListViewController<ItemType>: UITableViewController {
...
}

let listVC = SimpleListViewController<State>()
listVC.items = states
listVC.title = "SELECT STATE"
let navController = UINavigationController(rootViewController: listVC)

and I get Unrecognized selector -[Swift._IndirectArrayBuffer setTitle:] on both the title line and the navController line whichever comes first. Related you think? Did you ever figure this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.