Last active
March 18, 2017 10:47
-
-
Save keisei1092/1bb7e828e1715a778c0308f6039a08b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import UIKit | |
| import PlaygroundSupport | |
| struct Item { | |
| let id: Int | |
| let name: String | |
| } | |
| class ViewController: UITableViewController { | |
| let items: [Item] = [ | |
| Item(id: 1, name: "Bulbasaur"), | |
| Item(id: 2, name: "Ivysaur"), | |
| Item(id: 3, name: "Venusaur") | |
| ] | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| } | |
| override func numberOfSections(in tableView: UITableView) -> Int { | |
| return 1 | |
| } | |
| override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
| return items.count | |
| } | |
| override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
| let cell = UITableViewCell(style: .default, reuseIdentifier: "itemTableViewCell") | |
| let item = items[indexPath.row] | |
| cell.textLabel?.text = item.name | |
| return cell | |
| } | |
| override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
| let item = items[indexPath.row] | |
| let viewController = ItemViewController(frame: CGRect(x: 0, y: 0, width: 320, height: 480), item: item) | |
| navigationController?.pushViewController(viewController, animated: true) | |
| } | |
| } | |
| class ItemViewController: UIViewController { | |
| private let item: Item | |
| init(frame: CGRect, item: Item) { | |
| self.item = item | |
| super.init(nibName: nil, bundle: nil) | |
| self.title = self.item.name | |
| self.view = UIView(frame: frame) | |
| self.view.backgroundColor = UIColor.white | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| fatalError("init(coder:) has not been implemented") | |
| } | |
| } | |
| let rootViewController = ViewController() | |
| rootViewController.title = "Pokemon" | |
| let navigationController = UINavigationController(rootViewController: rootViewController) | |
| navigationController.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480) | |
| PlaygroundPage.current.liveView = navigationController.view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment