Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- protocol StateButtonDelegate {
- func didSelectState(state: String)
- }
- class StateTableViewController: UITableViewController {
- var delegateState:StateButtonDelegate?
- var selectedState:String = "AZ"
- let states = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA",
- "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD",
- "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ",
- "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC",
- "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"]
- override func viewDidLoad() {
- super.viewDidLoad()
- // Uncomment the following line to preserve selection between presentations
- // self.clearsSelectionOnViewWillAppear = false
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.rightBarButtonItem = self.editButtonItem()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- // MARK: - Table view data source
- override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- // #warning Incomplete implementation, return the number of sections
- return 1
- }
- override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of rows
- return self.states.count
- }
- override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
- // Configure the cell...
- cell.textLabel?.text = self.states[indexPath.row]
- if (self.states[indexPath.row] == self.selectedState) {
- cell.accessoryType = UITableViewCellAccessoryType.Checkmark
- } else {
- cell.accessoryType = .None
- }
- return cell
- }
- override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
- self.delegateState?.didSelectState(states[indexPath.row])
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement