override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
//表示表格视图只有一个区块
//缺省为 1,不写不影响运行
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return restaurantNames.count
}
//回传数列的数量和列数
//缺省为 0,不写视为无数据
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "datacell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = restaurantNames[indexPath.row]
cell.imageView?.image = UIImage(named: restaurantNames[indexPath.row])
//定义 cell 的内容
return cell
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "datacell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = restaurantNames[indexPath.row]
cell.imageView?.image = UIImage(named: restaurantNames[indexPath.row])
// [indexPath.row] 为枚举
return cell
}