2011-09-12 13 views
0

異なるデータを表示するが、同じテーブルを使用するUITableViewCellの2つのクラスがあります。拡張クラスでカスタマイズするときのUITableViewCellの問題

私はブールVARを使用して2つの段階でテーブルを埋めるためにしようとしているが、細胞は、ファーストクラスの割り当てを取得して、変異させることができないので、私は例外を取得ようだ...

basicaly私は

..私はステップ2でだと、細胞の種類を変更しようとすると、ブロック場合、位相== 2に [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] ]; で例外を与えたときに、拡張クラス

@interface PatientsCellNewPager : UITableViewCell { } 
@interface DoctorsCellNewPager : UITableViewCell { } 

コードブレーキをセルに持っています

これは、セルaデバッガには、最初の初期化からのDoctorsCellNewPager型があります。

どうすればいいですか? は、それはクラスの同じインスタンスを使用しますが、複数のレイアウトを使用して、スポットがひどいオプション

こと..wouldセルのレイアウトを定義し、同じページ上にある必要があり、ここに私のコード

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 



    if (phase==2) { //patient 


     PatientsCellNewPager *cell =(PatientsCellNewPager *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[PatientsCellNewPager alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 







     PatientsSet *set = (PatientsSet *)[patients_set objectAtIndex:indexPath.row];  

     NSLog(@"logg %d",indexPath.row);  


     [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] ]; 




      return cell; 

    } 
    else if (phase==1) { //doctor 


     DoctorsCellNewPager *cell =(DoctorsCellNewPager *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[DoctorsCellNewPager alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     } 





      // Set up the cell 

      DoctorsSet *set = (DoctorsSet *)[doctors_set objectAtIndex:indexPath.row];  


       [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] pass:YES ]; 





     return cell; 


    } 


    return nil; 

} 

は、ここに私のだですエラー

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DoctorsCellNewPager setData:cellid:]: unrecognized selector sent to instance 0x181690' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x323ef64f __exceptionPreprocess + 114 
    1 libobjc.A.dylib      0x36632c5d objc_exception_throw + 24 
    2 CoreFoundation      0x323f31bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102 
    3 CoreFoundation      0x323f2649 ___forwarding___ + 508 

答えて

1

これは非常に一般的な問題であり、多くの人々がそれを見つけました - ちょうど最近私はその問題にも対処しなければなりませんでした。

マット・ギャラガーは、彼のブログでそれを達成する方法についての素晴らしいチュートリアルを投稿:

Heterogeneous cells in a UITableViewController


をまあ、私はちょうどそれが仕事ができる方法についてのアイデアを得た。..
// THISは非常に実験的で、テストされていない

static NSString *PatientsCellIdentifier = @"PatientsCellNewPager"; 
static NSString *DoctorsCellIdentifier = @"DoctorsCellNewPager"; 

UITableViewCell *cell; 
if(patient) { 
    cell = [tableView dequeueReusableCellWithIdentifier:PatientsCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
     initWithStyle:UITableViewCellStyleDefault 
     reuseIdentifier:PatientsCellIdentifier] autorelease]; 
    } 
    // Setup cell for patient -> maybe you could use -configureCell:atIndexPath: 
} else if (doctor) { 
    cell = [tableView dequeueReusableCellWithIdentifier:DoctorsCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] 
     initWithStyle:UITableViewCellStyleDefault 
     reuseIdentifier:DoctorsCellIdentifier] autorelease]; 
    } 
    // Setup cell for doctor -> maybe you could use -configureCell:atIndexPath: 
} 

return cell; 

HTH

+0

これは非常にエレガントな解決策ではありません。私はセルのタイプをキャストする方法があると確信しています。 – PartySoft

+0

ちょうど答えを更新しました。あなたが探しています? –

+0

WOW、これはうまくいきました:)これは、コンパイラがセルが実際に異なっていることを知る方法です。ありがとう!!!あなたは男です – PartySoft

1

あなたが最後にpass:..のparamを逃している、とあなたは、[DoctorsCellNewPager setData:celled:]を呼び出しているメソッドは、パラメータpass設定されていません。したがって、passパラメータを追加すると問題なく動作します。

+0

は、他方はその引数を持っていない。これはそれ以上あなたをもたらした場合、私に教えてください、私はそれが問題を引き起こしていたかどうかを確認するために意図的にそれを終了しました...問題は、どういうわけか最初に割り当てられたセルのタイプです。 – PartySoft

関連する問題