異なるデータを表示するが、同じテーブルを使用する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
これは非常にエレガントな解決策ではありません。私はセルのタイプをキャストする方法があると確信しています。 – PartySoft
ちょうど答えを更新しました。あなたが探しています? –
WOW、これはうまくいきました:)これは、コンパイラがセルが実際に異なっていることを知る方法です。ありがとう!!!あなたは男です – PartySoft