前兩天已經試著用 storyboard 來做出一個 app,今天我們試著將一些資料已條列式的方式呈現出來。
相信用過智慧型手機一定都看過這樣的版型
沒錯!這就是所謂的 tableview,也就是我們今天要練習的重點
var restaurantNames = ["Cafe Deadend", "Homei", "Teakha", "Cafe Loisl", "Petite Oyster", "For Kee Restaurant", "Po's Atelier", "Bourke street Bakery", "Haigh's Chocolate", "Palomino Espresso", "Upstate", "Traif", "Graham Avenue Meats And Deli", "Waggle & Wolf", "Five Leaves", "Cage Lore ", "Confessional", "Barrafina", "Donostia", "Royal Oak", "CASK pub and kittchen"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return restaurantNames.count
8.2 這個view的內容要從哪裡來? cell是不是可以重複利用?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = restaurantNames[indexPath.row]
return cell
}