注意,我只是在学习 iOS 开发的基本知识。我有一个 TableView,它使用一个自定义单元格来切换其高度,以产生当您选择它时下拉的“抽屉”的效果。我几乎让它完全正常工作,但我有一个非常奇怪的问题。使用大于 12 的索引行选择的任何单元格都不会更改高度。 这是一个演示视频。 - http://d.chend.me/4NMU
我认为我正在以一种非常标准的方式初始化我的自定义单元格。
static NSString *CellIdentifier = @"DrawerCell";
NSDictionary *clip = self.isFiltered ? [self.filteredClips objectAtIndex:indexPath.row] : [self.clips objectAtIndex:indexPath.row];
DrawerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil] objectAtIndex:0];
}
我的 heightForRowAtIndexPath 委托(delegate)方法如下所示:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.selectedIndex == [NSNumber numberWithInt:indexPath.row])
{
return 126.0f;
}
else {
return 60.0f;
}
}
然后是 didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
if(self.selectedIndex == [NSNumber numberWithInt:indexPath.row])
{
self.selectedIndex = nil;
[tableView beginUpdates];
[tableView endUpdates];
NSLog(@"Selected Index: %@\nIndex Path Row: %i\n\n", self.selectedIndex, indexPath.row);
return;
}
//First we check if a cell is already expanded.
//If it is we want to minimize make sure it is reloaded to minimize it back
if(self.selectedIndex != nil)
{
self.selectedIndex = [NSNumber numberWithInt:indexPath.row];
[tableView beginUpdates];
[tableView endUpdates];
NSLog(@"Selected Index: %@\nIndex Path Row: %i\n\n", self.selectedIndex, indexPath.row);
return;
}
//Finally set the selected index to the new selection and reload it to expand
self.selectedIndex = [NSNumber numberWithInt:indexPath.row];
[tableView beginUpdates];
[tableView endUpdates];
NSLog(@"Selected Index: %@\nIndex Path Row: %i\n\n", self.selectedIndex, indexPath.row);
}
为什么大于 12 的索引行不起作用,而它们之前的所有内容都可以正常工作,这有什么明显的原因吗?附带说明一下,他们仍在接收触摸事件,并记录正确的索引路径行,只是不会显示抽屉。
最佳答案
您的问题可能(可能)是您通过==
比较NSNumbers。作为对象,它比较的是地址,而不是值。尝试使用 -isEqual:
代替。
关于ios - 扩展 UITableViewCell 不会扩展索引行 > 12,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15689723/