我有一个UITableView,我填充了我创建的多个子类UITableViewCells。所有子类UITableViewCell都可以正常工作,但是当UITableView中有足够的单元格来滚动整个视图时,我会滚动它。
这让我觉得错误在我的 tableView:tableViewcellForRowAtIndexPath 中的某处,但我不完全确定。
我正在使用 tableView的代码:tableViewcellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GetSeriesMacsDictionary *currentMac = [[GetSeriesMacsDictionary alloc] init];
currentMac = [recMacArray objectAtIndex:indexPath.row];
if (([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:5]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:7]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:13]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:14]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:17]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:19]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:32]])) {
static NSString *CellIdentifier = @"Cell";
cellSingle = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellSingle == nil) {
cellSingle = [[MacDataSingleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellSingle.nameLabel.text = MacStringForCell;
return cellSingle;
}
else if (([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:1]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:2]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:20]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:21]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:28]])) {
static NSString *CellIdentifier = @"Cell";
cellSihma = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellSihma == nil) {
cellSihma = [[MacDataSihmaTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellSihma.nameLabel.text = MacStringForCell;
cellSihma.SihmaLabelLabel.text = cardDictionary.SihmaCardNumber;
return cellSihma;
}
else if (([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:3]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:4]])) {
static NSString *CellIdentifier = @"Cell";
cellHP = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellHP == nil) {
cellHP = [[MacDataHPTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellHP.nameLabel.text = MacStringForCell;
cellHP.HPLabelLabel.text = cardDictionary.HPCardNumber;
return cellHP;
}
else if ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:11]]) {
static NSString *CellIdentifier = @"Cell";
cellHPB = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellHPB == nil) {
cellHPB = [[MacDataHPBTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellHPB.nameLabel.text = MacStringForCell;
cellHPB.HPBLabelLabel.text = cardDictionary.hPCCardNumber;
return cellHPB;
}
else if ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:12]]) {
static NSString *CellIdentifier = @"Cell";
cellHPP = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellHPP == nil) {
cellHPP = [[MacDataHPPTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellHPP.nameLabel.text = MacStringForCell;
cellHPP.HPPLabelLabel.text = cardDictionary.HPPCardNumber;
return cellHPP;
}
else if (([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:22]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:23]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:29]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:30]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:31]])) {
static NSString *CellIdentifier = @"Cell";
cellInco = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellInco == nil) {
cellInco = [[MacDataIncoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellInco.nameLabel.text = MacStringForCell;
cellInco.IncoLabelLabel.text = cardDictionary.iCCardNumber;
return cellInco;
}
else if (([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:16]]) || ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:27]])) {
static NSString *CellIdentifier = @"Cell";
cellSin = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellSin == nil) {
cellSin = [[MacDataSinTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellSin.nameLabel.text = MacStringForCell;
cellSin.SinLabelLabel.text = [NSString stringWithFormat:@"%d", seriesDictionary.Sin];
cellSin.SihmaLabelLabel.text = cardDictionary.SihmaCardNumber;
return cellSin;
}
else if ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:8]]) {
static NSString *CellIdentifier = @"Cell";
cellAqe = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellAqe == nil) {
cellAqe = [[MacDataAqeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellAqe.nameLabel.text = MacStringForCell;
cellAqe.qKitLabelLabel.text = currentMac.MacMiscDescription1;
cellAqe.pcLabelLabel.text = currentMac.MacMiscDescription2;
return cellAqe;
}
else if ([currentMac.Mac isEqualToNumber:[NSNumber numberWithInt:9]]) {
static NSString *CellIdentifier = @"Cell";
cellCue = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cellCue == nil) {
cellCue = [[MacDataCueTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cellCue.nameLabel.text = MacStringForCell;
cellCue.CueCamSetLabelLabel.text = currentMac.MacMiscDescription1;
cellCue.CueCarriageLabelLabel.text = currentMac.MacMiscDescription2;
cellCue.CueCutLabelLabel.text = currentMac.MacMiscDescription3;
return cellCue;
}
else {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *MacStringForCell = [self convertMacName:currentMac];
cell.textLabel.text = MacStringForCell;
return cell;
}
}
当桌面视图滚动时,当 cardDictionary。(myvar)被传递给任何具有(name)LabelLabel.text <的内容时,第一个新单元格会进入tablebiew。 / strong>我的应用程序失败了。
这是我得到的错误。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MacDataHPTableViewCell HPLabelLabel]: unrecognized selector sent to instance 0x16d53990'
*** First throw call stack:
(0x27b3ec1f 0x35316c8b 0x27b44039 0x27b41f57 0x27a73df8 0x1819fd 0x2b2c38c7 0x2b2c398b 0x2b2b90e1 0x2b0d12ff 0x2affb4d7 0x2aa23a0d 0x2aa1f3e5 0x2aa1f26d 0x2aa1ec51 0x2aa1ea55 0x2aa1892d 0x27b053b5 0x27b02a73 0x27b02e7b 0x27a51211 0x27a51023 0x2ee0a0a9 0x2b05d1d1 0x6e01d 0x35896aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是堆栈跟踪。
**<_NSCallStackArray 0x16fde6f0>(
0 ??? 0x04734a38 0x0 + 74664504,
1 CodeBrealer 0x0006dfa9 main + 0,
2 UIKit 0x2b2c38c7 <redacted> + 474,
3 UIKit 0x2b2c398b <redacted> + 54,
4 UIKit 0x2b2b90e1 <redacted> + 2268,
5 UIKit 0x2b0d12ff <redacted> + 186,
6 UIKit 0x2affb4d7 <redacted> + 514,
7 QuartzCore 0x2aa23a0d <redacted> + 136,
8 QuartzCore 0x2aa1f3e5 <redacted> + 360,
9 QuartzCore 0x2aa1f26d <redacted> + 16,
10 QuartzCore 0x2aa1ec51 <redacted> + 224,
11 QuartzCore 0x2aa1ea55 <redacted> + 324,
12 QuartzCore 0x2aa1892d <redacted> + 56,
13 CoreFoundation 0x27b053b5 <redacted> + 20,
14 CoreFoundation 0x27b02a73 <redacted> + 278,
15 CoreFoundation 0x27b02e7b <redacted> + 914,
16 CoreFoundation 0x27a51211 CFRunLoopRunSpecific + 476,
17 CoreFoundation 0x27a51023 CFRunLoopRunInMode + 106,
18 GraphicsServices 0x2ee0a0a9 GSEventRunModal + 136,
19 UIKit 0x2b05d1d1 UIApplicationMain + 1440,
20 CodeBrealer 0x0006e01d main + 116,
21 libdyld.dylib 0x35896aaf <redacted> + 2
)**
答案 0 :(得分:2)
问题是您正在使用相同的小区重用标识符&#34; cell&#34;对于不同的细胞类型。这意味着当您将单元格出列以便重复使用时,您可能无法获得所需的单元格类型 - 在崩溃的情况下,当您需要MacDataHPTableViewCell
时,您将MacDataHPBTableViewCell
出列 - 导致无法识别的选择器当您尝试访问该对象没有的属性时崩溃。
您需要为每种单元格类型使用唯一的单元格重用字符串。