【发布时间】:2017-02-16 13:47:17
【问题描述】:
谁能告诉我为什么它不为我返回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
}
}
【问题讨论】:
-
wczytaj 什么时候被调用?
-
如果您在 cellForRowAt 中设置断点,那么数组中的值是您所期望的吗?是您所期望的标签网点吗?
-
@JonRose 它是空的,如何从请求中获取价值?所有查看这里-> link
-
您在表格视图中在哪里调用
reloadData()?请注意,wartosc2仅返回one字符串(数组中键nazwa的最后一个值)
标签: ios swift uitableview core-data