2014-11-21 53 views
0

我在應用程序中實現了Core Data。 如果我運行它,我得到以下錯誤: 2014-11-21 13:29:28.400 MyApp[2630:37096] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116TableView CoreData錯誤:在...中的斷言失敗在Swift中

我不知道我做錯了什麼(我仍然很快學習)。

這是哪裏出現了錯誤的功能:

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

    var cell:MyTableViewCell = tableViewNotes.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell 
    cell.textLabel.text = "\(daten[indexPath.row].aufgabe)" 

    return cell 
} 

和發生錯誤的行:

var cell:MyTableViewCell = tableViewNotes.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell 

回答

0
used tabeView in place of tableViewNotes 

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

    var cell:MyTableViewCell = tabeView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MyTableViewCell 
    cell.textLabel.text = "\(daten[indexPath.row].aufgabe)" 

    return cell 
} 

讓我知道,如果它的工作原理。

+0

感謝您的快速回答!現在我在CoreData庫中獲得了一個斷點。但它似乎工作。我更遠了一步。 – hom 2014-11-21 13:23:40

0

您是否在故事板中使用了自定義單元格標識符名稱「單元格」? 如果不是。請將此「單元格」賦予您的自定義單元標識符。我希望它能工作

+0

非常感謝您的回答。我不使用故事板。我怎樣才能以編程方式做到這一點? – hom 2014-11-21 17:17:05

+0

然後,您必須在標識符爲「Cell」的MyTableViewCell的xib子類中取一個單元格。由於方法dequeueReusableCellWithIdentifier(標識符:字符串,forIndexPath indexPath:NSIndexPath) - > AnyObject //新出列方法保證了細胞被返回並適當調整,假設標識註冊 否則,你可以使用 VAR細胞:MyTableViewCell! = tableView.dequeueReusableCellWithIdentifier(「Cell」)作爲MyTableViewCell? 如果細胞==零 { 細胞=的UITableViewCell(樣式:.DEFAULT,reuseIdentifier: 「小區」) } – 2014-11-23 06:20:01