Last active
February 14, 2018 21:40
-
-
Save serhatsezer/bad941ad433464557705b615010c74f4 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 | |
| class OrdersViewController: UIViewController { | |
| // Create strong data source objects | |
| // Because tableView has a weak reference so it can be deallocated. | |
| let orderDataSource = OrderDataSource() | |
| let completedOrdersDataSource = CompletedOrdersDataSource() | |
| public enum OrderTabs: Int { | |
| case current | |
| case completed | |
| } | |
| @IBOutlet weak var segmentedControl: UISegmentedControl! | |
| @IBOutlet weak var tableView: UITableView! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| setupTableView() | |
| } | |
| func setupTableView() { | |
| tableView.dataSource = orderDataSource | |
| } | |
| @IBAction func segmentedControllerTapped(_ sender: UISegmentedControl) { | |
| if let tabs = OrderTabs(rawValue: sender.selectedSegmentIndex) { | |
| print("Selected tab: \(tabs)") | |
| switch tabs { | |
| case .current: | |
| tableView.dataSource = orderDataSource | |
| case .completed: | |
| tableView.dataSource = completedOrdersDataSource | |
| } | |
| tableView.reloadData() | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment