Created
October 28, 2014 21:52
-
-
Save jbrennan/a2aeb523b68701c50c22 to your computer and use it in GitHub Desktop.
Generic UIViewController subclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
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
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 ?