ここには2つの異なるテストケースがあります。ケース1の場合、これはCoreDataからのエントリの全量を印刷するために使用したもので、動作します。私はapp2で全く同じことをしようとしましたが、うまくいきません。私がしたいのは、すべてのコアデータエントリを持つ個々のセルです。Coreviewをテーブルビューのセルに印刷
APP1
override func viewDidLoad() {
super.viewDidLoad()
user = coreDataHandler.getSortedData()
for i in user! {
displayL.text = String(i.username)
}
}
APP2
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
user = coreDataHandler.getSortedData()
return user!.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = cctv.dequeueReusableCell(withIdentifier: "cell")
for i in user! {
cell?.textLabel?.text = String(describing: i.username)
return cell!
}
return cell!
}
「String」を作成するために必要な 'username'のタイプは何ですか?そして、決して* numberOfRowsInSection'にデータ*を取得しません。 – vadian