Last active
December 27, 2021 23:43
-
-
Save CodeNextPaco/9fa75ec405a618667b2c120780c9e0c9 to your computer and use it in GitHub Desktop.
Project1 ViewController (TableViewController)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UITableViewController { | |
var pictures = [String]() //empty array of Strings to hold our image file names. | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let fm = FileManager.default | |
let path = Bundle.main.resourcePath! | |
let items = try! fm.contentsOfDirectory(atPath: path) | |
for item in items{ | |
if item.hasPrefix("nssl"){ | |
//load a picture | |
pictures.append(item) | |
} | |
} | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return pictures.count | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "Picture", for: indexPath) | |
cell.textLabel?.text = pictures[indexPath.row] | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made public