Ich befülle eine Tabellenansicht mit Elementen in einer Liste, und wenn ich mehrere Elemente zur Tabellenansicht hinzufüge, sind alle Zellen außer der ersten leer. Und wenn ich die Zelle am untersten Ende des Bildschirms lösche, legt sie die Daten von dieser Zelle in die nächste Zelle nach oben. Ich bin mir nicht sicher, was ich falsch gemacht habe, aber hier ist mein Code, wenn jemand helfen kann.Popup-Tabellenansicht Zellen erstellt leere Zellen
import UIKit
// Initialize the list that populates the each cell in the table view
var list = [AnyObject]()
let cell = UITableViewCell(style: UITableViewCellStyle.default,
reuseIdentifier: "cell")
class FirstViewController: UIViewController, UITableViewDelegate,
UITableViewDataSource {
@IBOutlet weak var myTableView: UITableView!
// Declares how many rows the table view will have
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return (list.count)
}
// Populates each table view cell with items from each index in the list
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
// let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
// cell.accessoryType = .checkmark
// cell.textLabel?.textAlignment = .natural
// The text of the cell = the data of index that matches the index of the cell
cell.textLabel?.text = list[indexPath.row] as? String
// Sets the background color of the cell
// cell.backgroundColor = UIColor.clear
return cell
}
// Allows user to remove item from table view by swiping left
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
// if the user swiped left to delete an item from the table view
if editingStyle == UITableViewCellEditingStyle.delete
{
// remove the deleted item from the list and reload the data
list.remove(at: indexPath.row)
myTableView.reloadData()
}
}
Sie Sie müssen eine von tausend Tabellenansicht - Tutorials finden und sich die richtige Weise, um eine Zelle von der 'cellForRowAt'-Methode bereitzustellen. – rmaddy
@maddy Das ist, was ich versuche herauszufinden. Ich habe mir mehrere Tutorials angeschaut. Wenn Sie einen Einblick geben könnten, was ich mit meiner cellForRowAt-Methode falsch gemacht habe, wäre das hilfreich. – infiltratingtree