iOS: Table Views, Image Views, App Bundles & More…

Building your Project

Options to configure your project

Listing Images with FileManager

An example of a UIViewController

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

FileManager

let fm = FileManager.default

let path = Bundle.main.resourcePath!

let items = try! fm.contentsOfDirectory(atPath: path)

if item.hasPrefix(“nssl”) {

The pictures array will be created when the ViewController screen is created and exist for as long as the screen exists

pictures.append(item)

print(pictures)

Designing our Interface

An example of a UITableViewController

class ViewController: UITableViewController {

The current tab displaying at the right-hand pane is the identity inspector
The current tab displaying at the right-hand pane is the attributes inspector
Document outline
Assigning an identifier to the table view cell
numberOfRowsInSection method

override

func

tableView

_ tableView: UITableView

numberOfRowsInSection section: Int

→ Int

return pictures.count

cellForRowAt method

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

Building a Detail Screen

Creating a new file
Setting a view controller’s Storyboard ID
The Assistant Editor
An example of an IBOutlet

@IBOutlet

var imageView

UIImageView!

The process behind implicitly unwrapped optionals

Loading Images with UIImage

didSelectRowAt is an optional UITableViewController method

storyboard?.instantiateViewController(withIdentifier: “Detail”) as? DetailViewController

navigationController?.pushViewController(detailViewController, animated: true)

DetailViewController

imageView.image = UIImage(named: imageToLoad)

The Content Mode of the UIImageView can be found in the Attributes Inspector
Disclosure indicator

View Controller Lifecycles

viewDidLoad()

viewWillAppear()

viewDidAppear()

viewWillDisappear()

viewDidDisappear()

An example of viewWillAppear() and viewWillDisappear()

override

(_ animated: Bool)

super.viewWillAppear(animated) & super.viewWillDisappear(animated)

navigationController?.hidesBarsOnTap = Boolean Value

An example of the title property being set

title

An example of not needing to unwrap an optional string
An example of large titles being configured

navigationController?.navigationBar.prefersLargeTitles = true

navigationItem.largeTitleDisplayMode = .never

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store