ios - UITableViewCell 不显示 Swift 中的内容

标签 ios swift uitableview

代码是:

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/

相关文章:

ios - 在用户输入时将 UITextField 的文本格式化为电话号码

ios - 更改 UITableView 单元格颜色

ios - UITableView setEditing 不显示删除按钮

ios - iOS ShareExtension 应用程序中的数据共享问题

ios - Epos打印机iOS SDK

swift - 我如何在 swift 2 中重写这段和平的代码

ios - 按下 UITableViewCell 时调用方法

ios - 自定义tableviewCell内容宽度与tableView不同

ios - NavigationView 和 NavigationLink 在转换后不删除 View

ios - 旋转设备时调整 tableView 的大小