Skip to content

Instantly share code, notes, and snippets.

@CodeNextPaco
Last active December 27, 2021 23:43
Show Gist options
  • Save CodeNextPaco/9fa75ec405a618667b2c120780c9e0c9 to your computer and use it in GitHub Desktop.
Save CodeNextPaco/9fa75ec405a618667b2c120780c9e0c9 to your computer and use it in GitHub Desktop.
Project1 ViewController (TableViewController)
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
}
}
@CodeNextPaco
Copy link
Author

Made public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment