訂飲料App(5),搖晃手機隨機選飲料

  1. 將原本訂單頁面的飲料欄位從Label改成PickerView
更改新增/修改頁面的飲料欄位
  • 在main.storyborad設定PickerView的data source和 delegate
main.storyboard
  • 讓viewController遵從pickerView的protocol
DrinkDetailTableViewController.swift
  • 實作pickerView的protocol
DrinkDetailTableViewController.swift
  • 讓pickView顯示user選的飲料
DrinkDetailTableViewController.swift
DrinkDetailTableViewController.swift

2. 加入搖晃手機隨機選飲料的功能

使用 Int.random(in: 0..<drinks.count) 隨機選取一個index

DrinkDetailTableViewController.swift

--

--