Skip to content

Instantly share code, notes, and snippets.

@uchcode
Created February 15, 2020 00:23
Show Gist options
  • Save uchcode/1bfec4db30e252108c51d3ac36e5233a to your computer and use it in GitHub Desktop.
Save uchcode/1bfec4db30e252108c51d3ac36e5233a to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
var text: String?
override func loadView() {
super.loadView()
view.backgroundColor = .systemBackground
let label = UILabel()
view.addSubview(label)
label.text = text
label.translatesAutoresizingMaskIntoConstraints = false
label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
label.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
}
class TableViewController: UITableViewController {
override func loadView() {
super.loadView()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "greeting \(indexPath.row)"
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let viewController = ViewController()
viewController.text = "hello \(indexPath.row)"
let navigationController = UINavigationController(rootViewController: viewController)
showDetailViewController(navigationController, sender: self)
}
}
class SplitViewController: UISplitViewController, UISplitViewControllerDelegate {
override func loadView() {
super.loadView()
delegate = self
let viewController = TableViewController()
viewController.title = "Hello World"
let navigationController = UINavigationController(rootViewController: viewController)
navigationController.navigationBar.prefersLargeTitles = true
let empty = UIViewController()
empty.view.backgroundColor = .systemBackground
viewControllers = [navigationController, empty]
}
}
import PlaygroundSupport
PlaygroundPage.current.wantsFullScreenLiveView = true
PlaygroundPage.current.setLiveView(SplitViewController())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment