[英]An empty cell on tableView + CoreData
Can someone tell me why it don't return cell
for me? 有人可以告诉我为什么它不为我返回cell
吗? I really don't now why. 我现在真的不知道为什么。 On " cellTableViewCell
" I have only outlets with label's. 在“ cellTableViewCell
”上,我只有带有标签的插座。 Or I need to read at func viewWillAppear
? 或者我需要阅读func viewWillAppear
吗?
var nazwaTab:[String] = []
func getContext() -> NSManagedObjectContext {
let appDelegate = UIApplication.shared.delegate as? AppDelegate
return (appDelegate?.persistentContainer.viewContext)!
}
func wczytaj(wartosc:String) -> String {
var wartosc2 = wartosc
let request: NSFetchRequest<Ostatnie> = Ostatnie.fetchRequest()
do {
let result = try getContext().fetch(request)
for liczby in result {
if let str = liczby.value(forKey: "nazwa") as? String
{
wartosc2 = str
nazwaTab.append(wartosc2)
nazwaTab.last
}
print(nazwaTab)
}
} catch {
print(error)
}
return wartosc2
}
}
extension tabViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return nazwaTab.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! cellTableViewCell
cell.dlugoscLabel.text = dlugoscTab[indexPath.row] as! String
cell.nazwaLabel.text = nazwaTab[indexPath.row]
cell.szerokoscLabel.text = szerokoscTab[indexPath.row] as! String
return cell
}
}
I think you should set UITableViewDelegate like this : class tabViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
我认为您应该像这样设置UITableViewDelegate: class tabViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
and in viewDidLoad: 并在viewDidLoad中:
tableView.delegate = self
tableView.dataSource = self
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.