【发布时间】:2018-06-30 03:15:00
【问题描述】:
我的表格视图中有一个 UILabel,我手动将标签设置为 1
我有这段代码,当我运行应用程序时它运行良好。我确实向下滚动并工作,名称填写正确。
但是当我单击单元格并再次向下滚动时,有时单元格中的标签会出现如下错误:
无法识别的选择器发送到实例 0x7fc01d74a710
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Mediprecios.RotatedView setText:]:无法识别的选择器发送到实例 0x7f8d9073f4f0” 并在 labelName.text = name 的方法 cellForRowAtIndexPath 中崩溃;
po 0x7fc01d74b370
<Mediprecios.RotatedView: 0x7fc01d74b370; frame = (0 100; 345 100); alpha = 0; tag = 1; layer = <CALayer: 0x600000827dc0>>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
FoldingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
UILabel *labelName = [cell viewWithTag:1];
NSString *name = [displayItems objectForKey:@"Name"];
labelName.text = name;
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
FoldingCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.isAnimating) {
return;
}
double duration = 0;
NSNumber *height = [self.cellHeights objectAtIndex:indexPath.row];
bool cellIsCollapsed = height.floatValue == self.kCloseCellHeight;
if (cellIsCollapsed) {
[self.cellHeights setObject:[NSNumber numberWithFloat:self.kOpenCellHeight] atIndexedSubscript:indexPath.row];
[cell unfold:YES animated:YES completion:nil];
duration = 0.5;
} else {
[self.cellHeights setObject:[NSNumber numberWithFloat:self.kCloseCellHeight] atIndexedSubscript:indexPath.row];
//[cell selectedAnimation:false animated:true completion: nil];
[cell unfold:NO animated:YES completion:nil];
duration = 0.8;
}
[UIView animateWithDuration:duration delay:0 options:0 animations:^{
[tableView beginUpdates];
[
tableView endUpdates];
} completion:nil];
}
【问题讨论】:
-
请显示完整的错误信息。并指出导致错误的确切代码行。
-
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[Mediprecios.RotatedView setText:]:无法识别的选择器发送到实例 0x7f8d9073f4f0”并且在 labelName.text = name 中的方法 cellForRowAtIndexPath 中崩溃;
-
不处理标签,为什么不提供对
FoldingCell类的labelName属性的只读访问权限,就像textLabel在UITableViewCell中提供的一样。 -
和edit 你的问题与错误。细节属于问题,而不是 cmets。
-
这是 Xcode 的一个错误,只是我将标签号从其他类似 1001 更改为完美。
标签: objective-c xcode uitableview