Advertisement
Guest User

Untitled

a guest
Nov 9th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. import UIKit
  2.  
  3.  
  4. protocol StateButtonDelegate {
  5. func didSelectState(state: String)
  6. }
  7.  
  8. class StateTableViewController: UITableViewController {
  9. var delegateState:StateButtonDelegate?
  10. var selectedState:String = "AZ"
  11. let states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA",
  12. "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD",
  13. "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
  14. "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
  15. "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
  16.  
  17.  
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20.  
  21. // Uncomment the following line to preserve selection between presentations
  22. // self.clearsSelectionOnViewWillAppear = false
  23.  
  24. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  25. // self.navigationItem.rightBarButtonItem = self.editButtonItem()
  26. }
  27.  
  28. override func didReceiveMemoryWarning() {
  29. super.didReceiveMemoryWarning()
  30. // Dispose of any resources that can be recreated.
  31. }
  32.  
  33. // MARK: - Table view data source
  34.  
  35. override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
  36. // #warning Incomplete implementation, return the number of sections
  37. return 1
  38. }
  39.  
  40. override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  41. // #warning Incomplete implementation, return the number of rows
  42. return self.states.count
  43. }
  44.  
  45.  
  46. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  47. let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
  48.  
  49. // Configure the cell...
  50. cell.textLabel?.text = self.states[indexPath.row]
  51.  
  52. if (self.states[indexPath.row] == self.selectedState) {
  53. cell.accessoryType = UITableViewCellAccessoryType.Checkmark
  54. } else {
  55. cell.accessoryType = .None
  56. }
  57.  
  58. return cell
  59. }
  60.  
  61. override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  62. self.delegateState?.didSelectState(states[indexPath.row])
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement