代码是:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = delegate.managedObjectContext!
let fetchRequest = NSFetchRequest(entityName: "Inspiration")
var error: NSError?
let fetchedResults = managedContext.executeFetchRequest(fetchRequest, error: &error) as? [NSManagedObject]
inspirations = fetchedResults!
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
let content = inspirations[indexPath.row]
cell.textLabel?.text = content.valueForKey("name") as? String
return cell
}
fetchedResults
中有一些值,它不应该有问题,UITableViewCell
的实现应该有问题。
最佳答案
确保您为 UITableView 设置了委托(delegate)和数据源。
尝试将其添加到 viewDidLoad 函数中。
myTableView.delegate = self
myTableView.dataSource = self
关于ios - UITableViewCell 不显示 Swift 中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31230184/