我正在制作待办事项应用程序。我使用核心数据。在里面我有三个对象。在 (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
最佳答案
确保您的 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/