Last active
January 31, 2020 07:01
-
-
Save paulw11/82c4b05310e4edac98db1345f18cfbfe 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
class ViewController: UIViewController { | |
@IBOutlet weak var tableview: UITableView! | |
@IBOutlet weak var segmentedControl: UISegmentedControl! | |
var followers = [String]() | |
var following = [String]() | |
var tableData = [String]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
for i in 1...10000 { | |
following.append("Following \(i)") | |
followers.append("Follower \(i)") | |
} | |
self.tableData = followers | |
self.segmentedControl.selectedSegmentIndex = 0 | |
// Do any additional setup after loading the view. | |
} | |
@IBAction func segmentChanged(_ sender: UISegmentedControl) { | |
switch sender.selectedSegmentIndex { | |
case 0: | |
self.tableData = followers | |
case 1: | |
self.tableData = following | |
default: | |
return | |
} | |
self.tableview.reloadData() | |
} | |
} | |
extension ViewController: UITableViewDataSource { | |
func numberOfSections(in tableView: UITableView) -> Int { | |
return 1 | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return tableData.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) | |
cell.textLabel?.text = self.tableData[indexPath.row] | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment