详细信息(字幕)文本不会出现.不过,这些数据是可用的,因为当添加println()调用时,它会将可选("数据")打印到控制台,其中包含预期的数据.在情节提要中,UITableViewController设置为正确的类,表视图单元格样式设置为"Subtitle",重用标识符设置为"Cell".如何获取要显示的字幕信息?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

    dispatch_async(dispatch_get_main_queue(), { () -> Void in

        cell.textLabel.text = self.myArray[indexPath.row]["title"] as? String
        cell.detailTextLabel?.text = self.myArray[indexPath.row]["subtitle"] as? String

        println(self.myArray[indexPath.row]["subtitle"] as? String)
        // The expected data appear in the console, but not in the iOS simulator's table view cell.

    })
    return cell
}

推荐答案

这里也有同样的问题(据我所知,可能是iOS 8中的一个bug?),我们就是这样解决的:

  1. 从故事板中删除原型单元

  2. 删除此行:

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

  1. 替换为以下代码行:
let cellIdentifier = "Cell"
            
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
if cell == nil {
    cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: cellIdentifier)
}

Update for Swift 3.1

let cellIdentifier = "Cell"
    
var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
if cell == nil {
    cell = UITableViewCell(style: UITableViewCellStyle.value2, reuseIdentifier: cellIdentifier)
}

Update for Swift 4.2 - Simplified

let cell = UITableViewCell(style: UITableViewCell.CellStyle.value2, reuseIdentifier: "cellId")

Update for Swift 5 - Simplified

let cell = UITableViewCell(style: .value2, reuseIdentifier: "cellId")

Swift相关问答推荐

WWDC Swift并发会话中的厨房服务示例令人困惑

是否有一个Kotlin等价的Swift s @ AddendableReport注释'

像WebSocket一样接收实时更新,但通过异步/等待或组合

异步/等待函数的XCTAssertThrowsError

以编程方式使UIView居中,而不影响UIKit中其他UI类的位置

Swift Property Wrappers-Initialization 失败并显示无法将‘Double’类型的值转换为预期的参数类型

数组中某些元素的总和

领域异常中的相同方法:发送到实例的无法识别的 Select 器

确定路径是否相交的有效方法

UIButton 配置不更新按钮标题

用逻辑运算符保护让

令人满意的 var body:协议扩展中的一些视图

ZStack 中的 ProgressView 与 View 的行为不同

理解 Swift 2.2 Select 器语法 - #selector()

使用自定义相机拍照 iOS 11.0 Swift 4. 更新错误

从 NSData 对象在 Swift 中创建一个数组

如何快速截取 UIView 的屏幕截图?

如何在今天的扩展(iOS)中访问 CoreData 模型

自定义 Google 登录按钮 - iOS

如何将多个枚举值作为函数参数传递