代码是:
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
的实现应该是错误的。
答案 0 :(得分:3)
确保您为UITableView设置了delegate和dataSource。
尝试在viewDidLoad func中添加它。
myTableView.delegate = self
myTableView.dataSource = self