ios - Swift 和 EXT_BAD_ACCESS 中的详细文本标签

标签 ios xcode swift core-data

我正在制作待办事项应用程序。我使用核心数据。在里面我有三个对象。在 (SecondViewController) 中保存成功。但是当我加载 TableView Controller 时,应用程序立即崩溃。如果我删除 detailTextLabel 应用程序工作正常。

我的核心数据代码:

import Foundation
import CoreData

@objc(Note)
class Note: NSManagedObject {
    @NSManaged var mynote: String
    @NSManaged var mydate: NSDate
    @NSManaged var mytime: String
}

我的表格 View Controller 代码

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("CellNote", forIndexPath: indexPath) as! UITableViewCell

    if var cellContact = fetchedResultsController?.objectAtIndexPath(indexPath) as? Note {
        cell.textLabel!.text = cellContact.mynote
        cell.detailTextLabel!.text = cellContact.mytime
    }

    return cell

A picture of the error .

最佳答案

确保您的 UITableViewStyle 符合详细 View 类型。使用选项。在展开之前测试你的值。

if let time = cellContact.mytime {
    println(time)
    // Place a breakpoint here to see if the time value exists first before assigning to detailTextLabel.text
    cell.detailTextLabel?.text = time
}

问题很可能出在您的日期转换上。试试这个

var formatter = NSDateFormatter()
formatter.dateStyle = NSDateFormatterStyle.ShortStyle
formatter.timeStyle = NSDateFormatterStyle.ShortStyle
let timeStamp = formatter.stringFromDate(NSDate())
// Set your mytime here and save

关于ios - Swift 和 EXT_BAD_ACCESS 中的详细文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29758071/

相关文章:

ios - 在序列之间存储数据

ios - 如何向使用 UIBezierPath 创建的 CAShapeLayer 添加渐变颜色

ios - 如何将 UITabBarController 导航到 ViewController?

ios - 使用 Xcode 4.5 本地化 Localizable.strings

swift - UITableView 不在 UIView 容器内滚动

swift 3 |核心数据 |自定义实体

iOS 动画 >> 如何为单个对象设置动画以移动多个位置

iphone - 将 CGPDFPageRef 转换为整数

ios - Xcode 方法自动完成仅显示某些类

ios - 如何为 iOS 应用程序添加启动视频