2012-05-05 22 views
0

複数の行を表示するUITableViewを作成しようとしていましたが、これは2つのカスタムセルをXIBファイルからロードする必要があります。すでに2つのUITableViewCellのを作成しましたが、それはアプリを動作させるための試みは、単に(SIGARBRT)をクラッシュしたときに、私はそれだけでは怒鳴るコードに誤りであると仮定することができますUITableViewで複数の行タイプを表示する

- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *CellIdentifier1 = @"ACell"; 
    ACell *cell1 = (ACell *)[userSettingsTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 

    static NSString *CellIdentifier2 = @"BCe;;"; 
    BCell *cell2 = (BCell *)[userSettingsTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 

    if([indexPath row] == 0) return cell1; 
    if([indexPath row] == 1) return cell2; 
    return nil; 

    return cell1; 
} 

何かが、事前のおかげで便利ですしてください!

エラーメッセージ:

2012-05-05 18:21:49.256 StrangeThings[4388:f803] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061 
2012-05-05 18:21:49.258 StrangeThings[4388:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 
*** First throw call stack: 
(0x13cf022 0x1560cd6 0x1377a48 0x9b02cb 0xb3d28 0xb43ce 0x9fcbd 0xae6f1 0x57d42 0x13d0e42 0x1d87679 0x1d91579 0x1d164f7 0x1d183f6 0x1da5160 0x29f30 0x13a399e 0x133a640 0x13064c6 0x1305d84 0x1305c9b 0x12b87d8 0x12b888a 0x19626 0x1af2 0x1a65 0x1) 
terminate called throwing an exception(lldb) 
+0

とするものですエラーメッセージ? – Anila

+0

質問が更新されました。 – Mateus

+0

デバッグして戻り値がnullでないことを確認してください。 – Anila

答えて

1

最初THIGがあなたのセル識別子を変更では、開始時に小さな文字で、のような内陣、CELLBを使用し、ウルクラスとしてそれを名前を付け、特別なcharectors

を避けることはありません第二は 使用、それはテーブルビューはは再使用されますキューにセルが存在しない場合、それは任意のセルを返しません、あなたが任意のセルにメモリを割り当てていないことである

- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    static NSString *CellIdentifier1 = @"cellA"; 
    ACell *cell1 = (ACell *)[userSettingsTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
if (cell1== nil) cell1 = [ACell alloc] init.........// your ACell class initlizer 
    static NSString *CellIdentifier2 = @"cellB"; 
    BCell *cell2 = (BCell *)[userSettingsTableView dequeueReusableCellWithIdentifier:CellIdentifier2]; 
if(cell2== nil) cell2 = [BCell alloc] init.........// BCell initializer 
    if([indexPath row] == 0) return cell1; 
    if([indexPath row] == 1) return cell2; 
    return nil; 

    return cell1; 
} 
関連する問題