Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.14 KB | None | 0 0
  1. //
  2. //  BairrosTableViewController.swift
  3. //  TuristandoRio
  4. //
  5. //  Created by abiliojr on 9/27/16.
  6. //  Copyright © 2016 abittencourt. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class BairrosTableViewController: UITableViewController {
  12.    
  13.     var pontosT:NSArray?
  14.     var bairros:Array<String>!
  15.     let showListLocaisIdentifier = "showListLocais"
  16.     let identifier = "bairroCell"
  17.    
  18.     override func viewDidLoad() {
  19.         super.viewDidLoad()
  20.         if let bundlePath = NSBundle.mainBundle().pathForResource("Places", ofType: "plist"){
  21.             if let dicionario = NSDictionary(contentsOfFile: bundlePath){
  22.                 pontosT = dicionario["places"]! as? NSArray
  23.                
  24.                 bairros = []
  25.                
  26.                 for a in pontosT! {
  27.                     if(!bairros.contains(a.valueForKey("Bairro") as! String)){
  28.                         bairros.append(a.valueForKey("Bairro") as! String)
  29.                     }
  30.                 }
  31.                
  32.                 tableView.reloadData()
  33.             }
  34.         }
  35.     }
  36.    
  37.     override func tableView(tableView: UITableView, numberOfRowsInSection section: Int)-> Int{
  38.         return (bairros.count)
  39.     }
  40.    
  41.     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell{
  42.        
  43.        
  44.         var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(identifier)
  45.        
  46.         if cell == nil{
  47.             cell = UITableViewCell(style: .Default, reuseIdentifier: identifier)
  48.         }
  49.  
  50.         cell?.textLabel?.text = bairros?[indexPath.row]        
  51.         cell?.textLabel?.textColor = UIColor.whiteColor()
  52.        
  53.         return cell!
  54.     }
  55.    
  56.     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  57.         if let index = tableView.indexPathForSelectedRow{
  58.             if  segue.identifier == showListLocaisIdentifier{
  59.                 if let destination = segue.destinationViewController as? ListLocaisTableViewController{
  60.                 destination.bairroSelecionado = bairros![index.row]
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement