要在iPhone应用程序中为TableView填充简单数据,您需要遵循以下步骤:
class MasterViewController: UITableViewController {
var data = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
let item = data[indexPath.row]
cell.textLabel?.text = item
return cell
}
这就是在iPhone应用程序中为TableView填充简单数据的方法。您可以根据需要自定义数据模型和单元格样式。
领取专属 10元无门槛券
手把手带您无忧上云