Advertisement
Guest User

iTunesSharing

a guest
May 27th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. //
  2. // TableViewController.swift
  3. // Desafio iTunesSharing
  4. //
  5. // Created by Orlando Amorim on 27/05/15.
  6. // Copyright (c) 2015 Orlando Amorim. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class TableViewController: UITableViewController {
  12.  
  13. var array = [AnyObject]()
  14.  
  15. @IBOutlet weak var pegaArquivo: UIBarButtonItem!
  16.  
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19. pegarArquivo(pegaArquivo)
  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 Potentially incomplete method implementation.
  37. // Return the number of sections.
  38. return 1
  39. }
  40.  
  41. override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  42. // #warning Incomplete method implementation.
  43. // Return the number of rows in the section.
  44. return array.count
  45. }
  46.  
  47.  
  48. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  49. let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
  50.  
  51. // Configure the cell...
  52.  
  53. cell.textLabel?.text = array[indexPath.row] as String
  54.  
  55. return cell
  56. }
  57.  
  58.  
  59. /*
  60. // Override to support conditional editing of the table view.
  61. override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
  62. // Return NO if you do not want the specified item to be editable.
  63. return true
  64. }
  65. */
  66.  
  67. /*
  68. // Override to support editing the table view.
  69. override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
  70. if editingStyle == .Delete {
  71. // Delete the row from the data source
  72. tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
  73. } else if editingStyle == .Insert {
  74. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  75. }
  76. }
  77. */
  78.  
  79. /*
  80. // Override to support rearranging the table view.
  81. override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
  82.  
  83. }
  84. */
  85.  
  86. /*
  87. // Override to support conditional rearranging of the table view.
  88. override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
  89. // Return NO if you do not want the item to be re-orderable.
  90. return true
  91. }
  92. */
  93.  
  94. /*
  95. // MARK: - Navigation
  96.  
  97. // In a storyboard-based application, you will often want to do a little preparation before navigation
  98. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  99. // Get the new view controller using [segue destinationViewController].
  100. // Pass the selected object to the new view controller.
  101. }
  102. */
  103. @IBAction func pegarArquivo(sender: UIBarButtonItem) {
  104.  
  105. var documentos = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! String
  106.  
  107. let gerenciadorArquivos = NSFileManager.defaultManager()
  108.  
  109. if let arquivos = gerenciadorArquivos.contentsOfDirectoryAtPath(documentos, error: nil){
  110. for arquivo in arquivos{
  111. array = [arquivo]
  112. }
  113. }
  114. println(array)
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement