簡體   English   中英

tableView + CoreData上的一個空單元格

[英]An empty cell on tableView + CoreData

有人可以告訴我為什么它不為我返回cell嗎? 我現在真的不知道為什么。 在“ cellTableViewCell ”上,我只有帶有標簽的插座。 或者我需要閱讀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
}
}

我認為您應該像這樣設置UITableViewDelegate: class tabViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

並在viewDidLoad中:

tableView.delegate = self
tableView.dataSource = self

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM