我想在應用程序中完成對視圖控制器的簡單添加,但它證明是一個挑戰。我正在試圖添加一個基本上做的列表到這個視圖控制器。我有一個數組'list',當我運行應用程序時應該顯示其項目,但是我得到空白。我已經檢查了常見的錯誤,例如沒有將表視圖連接到視圖控制器,對tableview等沒有約束。我看不出我做錯了什麼,但希望有一組不同的眼睛能指出我正確的方向。代碼如下:在Swift中使用數組的表視圖
class ThirteenthViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var list = ["hero", "The Boys of Brighton Beach", "This Time is Different", "BS Book"]
@IBOutlet weak var collectionTableView: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (list.count)
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.textLabel?.text = list[indexPath.row]
return(cell)
}
func tableView( tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
if editingStyle == UITableViewCellEditingStyle.delete
{
self.list.remove(at: indexPath.row)
collectionTableView.reloadData()
}
}
@IBAction func dismissCollection(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
你是否檢查過你的代碼是否被調用,如果有的話,返回什麼值? –
對不起。我還很新,所以我該怎麼做?謝謝! –
斷點,打印語句,類似的東西。 –