2012-03-01 38 views
2

實現的UITableView與自定義的UITableViewCell與下面碼UITableView的數據源必須返回從一個的tableView細胞:的cellForRowAtIndexPath /斷言失敗消息

@interface ProfileSaveViewController : UITableViewController 
    { 
     UITableViewCell *cell0; 
     UITableViewCell *cell1; 
     UITableViewCell *cell2; 
     UILabel *cell2Label; 
    } 

    @property (nonatomic, retain) IBOutlet UITableViewCell *cell0; 
    @property (nonatomic, retain) IBOutlet UITableViewCell *cell1; 
    @property (nonatomic, retain) IBOutlet UITableViewCell *cell2; 
    @property (nonatomic, retain) IBOutlet UILabel *cell2Label; 

    @end 

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath*)indexPath 
    { 
     if([indexPath row] == 0) return cell0; 
     if([indexPath row] == 1) return cell1; 
     if([indexPath row] == 2) return cell2; 
     return nil; 
    } 

follwing消息運行應用程序時就來了。

*在聲明失敗 - [UITableView的_createPreparedCellForGlobalRow:withIndexPath:],/SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072 2012-03-01 11:11:31.984 TestSplitView [765:F803] *終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「UITableView的數據源必須的tableView返回細胞:的cellForRowAtIndexPath:」

回答

8

你被問了小區和返回nil(或者別的東西,這不是一個UITableViewCell )。就這麼簡單。

我看到兩種可能性:

  • 您正在返回的數字大於3從tableView:numberOfRowsInSection:較大。別。

  • 一個或多個cell#網點沒有連接到您的筆尖,或者沒有連接到UITableViewCell(或子類)。將它們正確連接起來。

+0

- (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分 { 返回3; } – Susitha 2012-03-01 06:17:31

+1

那麼這是另一種可能性。你還沒有把所有的網點都連接到表格視圖單元格上。 – 2012-03-01 06:18:50

+0

您的意思是「通過設置引用outlet atrribute」來「掛鉤」嗎? – Susitha 2012-03-01 06:19:14

1
+0

這是完全正常,如果你有一個少數細胞產生一組靜態表視圖細胞。 – 2012-03-01 06:13:23

+0

事實上該技術在* [表視圖編程指南爲iOS](https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//中描述apple_ref/DOC/UID/TP40007451-CH7-SW32)*標題「靜態行內容的技術」下。 – 2012-03-01 06:19:45

4

如果您使用的是自定義的UITableViewCell,也有可能是你忘了確定 「標識符」 ON 「UTILITES方」 - > 「屬性檢查器」 選項卡。

希望這會有所幫助。

0
/* Dynamic Prototype cell in UITableView */ 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView ==tblUser) { 
     switch (indexPath.row) 
     { 
      case 0: 
       return Cell_0; 
       break; 
      case 1: 
       return Cell_1; 
       break; 
      case 2: 
       return Cell_2; 
       break; 
      case 3: 
       return Cell_3; 
       break; 
      case 4: 
       return Cell_4; 
       break; 
      case 5: 
       return Cell_04; 
       break; 
      case 6: 
       return Cell_5; 
       break; 
      case 7: 
       return Cell_6; 
       break; 
      case 8: 
       return Cell_7; 
       break; 
      default: 
       return nil; 
       break; 
     } 
    }else 
return nil 
} 
相關問題