我对苹果开发绝对是新手。我目前正在使用主要细节概念构建iPad。在我的详细信息视图中,我有一些基本元素(例如文本字段等)以及一个容器,并且在该容器内是tableView。我正在遵循此指南:https : //www.youtube.com/watch?v=AaCfwqzH9SQ
我的问题是我的虚拟数据没有出现在表视图中。这只是一张空桌子。但是它确实打印出了我包含在viewDidLoad方法中的日志消息。
这是我的类多数民众赞成在连接到表视图:
import UIKit
class TaskTableViewController: UITableViewController {
var Array = [String]()
override func viewDidLoad() {
super.viewDidLoad()
print("IN THE TASKBAR")
Array = ["ffff","ddd","sss"]
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return Array.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
//THIS IS WHER YOU'D PROGRAM YOUR TASK THINGS
cell.textLabel?.text = Array[indexPath.row]
// Configure the cell...
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
numberOfSections
不应该返回zero
。要在您tableView
的至少一个区域中显示一些单元格,应该可用。
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
reloadData
在您向其中插入内容后,还调用tableViewArray
override func viewDidLoad() {
super.viewDidLoad()
print("IN THE TASKBAR")
Array = ["ffff","ddd","sss"]
self.tableView.reloadData()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem
}
假设此方法将在单击按钮时执行。
func didClickedOnEditButton(button: UIButton){
//First add string into your array
Array.append("This is the newly inserted String")
//Then ask your TableView to reload Everything
tableView.reloadDate()
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句