我有 2 个用于 UITableViewCell 的类,它们显示不同的数据,但它们使用同一个表。
我正在尝试使用 bool var 分两步填充表格,但似乎我得到了一个异常,因为单元格获得了第一类分配并且不能变异......
基本上我必须单元扩展类
@interface PatientsCellNewPager : UITableViewCell { }
@interface DoctorsCellNewPager : UITableViewCell { }
当我在第 2 步并尝试更改单元格的类型并 [cell setData:set cellid:[NSString stringWithFormat:@"%d",indexPath.row] ];
在 phase==2 if block 时给出异常时,代码会停止。
这是因为根据调试器的单元格仍然具有第一次初始化的类型 DoctorsCellNewPager....
不然怎么办??它必须在同一页面上使用相同的类实例,但使用多个布局并在现场定义单元格布局..这将是一个糟糕的选择
这是我的代码
// 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