Skip to content

Instantly share code, notes, and snippets.

@e-sung
Created May 9, 2019 14:22
Show Gist options
  • Save e-sung/2e99e28923f8c95bdbb0a3363afb8bd3 to your computer and use it in GitHub Desktop.
Save e-sung/2e99e28923f8c95bdbb0a3363afb8bd3 to your computer and use it in GitHub Desktop.
// 옛날 버전. "세그먼트 콘트롤이 눌리면 테이블뷰를 리로드하라"로 밖에 읽히지 않는다.
@IBAction func segementSelected(_ sender: UISegmentedControl) {
tableView.reloadData()
}
// 리팩토링버전. "선택된 세그먼트에 해당되는 데이터로 테이블을 채워라"라는 의도가 보인다.
@IBAction func segementSelected(_ sender: UISegmentedControl) {
tableView.dataSource = dataSources[sender.selectedSegmentIndex]
tableView.reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment