1/19

Lecture Mobile Application Development (119310)

iOS Development - Framework Basics Part II

2/19

Agenda

3/19

Properties

center 70%

4/19

Properties

center 70%

5/19

Properties Assignment

6/19

Protocols in Swift

7/19

Protocols in Swift

protocol SomeProtocol {
    // protocol definition goes here
}

class SomeClass: SomeSuperClass, FirstProtocol, SomeProtocol {
    // class definition goes here
}
8/19

Protocols in Swift

protocol SomeProtocol {

    // a settable Property must be implemented using 
    // var in the implementing class
    var mustBeSettable: Int { get set } 

    // a only gettable Property should be implented using let
    var doesNotNeedToBeSettable: Int { get }

}
9/19

Protocols in Swift

protocol RandomNumberGenerator {

    func random() -> Double

}
10/19

Protocol Assignment

11/19

UITableViewController

  • UIKit class to create lists
    • Similar to ListActivity on Android
  • Contains a UITableView to show items in a list
    • Similar to the ListView on Android
  • Makes use of the Delegate pattern by 
implementing, e.g. following Protocols
    • UITableViewDelegate
    • UITableViewDataSource
      • Similiar to the ListAdapter on Android
50%
12/19

UITableViewDelegate

13/19

UITableViewDelegate

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("Selected row \(indexPath.item)")
    }

14/19

UITableViewDataSource

15/19

UITableViewDataSource


// Override to define the number of sections for the table
override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

// Override to define the number of rows in each section 
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return shoppingList.count
    }

// Override to define the cell for a given row
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)

        // Configure the cell...
        
        cell.textLabel?.text = shoppingList[indexPath.item]

        return cell
    }
16/19

UITableView

  • The UITableView defines the visible list that is controlled by the UITableViewController
  • Inherits from UIScrollView
  • Can have one of two styles
    • UITableViewStylePlain
    • UITableViewStyleGrouped
  • Each row in the UITableView is defined by a UITableViewCell
50%
17/19

UITableViewCell

  • The UITableViewCell defines the content of the cells that appear in a UITableView
  • Inherits from UIView
  • Has a predefined textLabel, a detailTextLabel and an imageView Property
  • Has a „Reuse Identifier“ to save resources when rendering
  • Supports different Cell-Styles
    • Basic
    • Right Detail
    • Left Detail
    • Subtitle
50%
18/19

TableView Assignment

19/19

References