ios - 扩展 UITableViewCell 不会扩展索引行 > 12

标签 ios xcode uitableview

注意,我只是在学习 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/

相关文章:

ios - SSErrorDomain 错误代码 109。NewsStand 从 Amazon S3 下载

iphone - 带有 Facebook 单点登录的 iOS 应用程序中的“赞”按钮

iphone - xcode iphone触摸点画

ios - IPA 大小和性能

ios - tableview 连接到数据源和委托(delegate) - 如何

ios - 使用 iOS 8 在 uitableview 中显示的图像与 iOS 7 不同

ios - Xcode 应用程序包 ID 与代码签名 ID 不匹配

ios - UICollectionViewCell IBAction 影响多个单元格

ios - 如何检查数组中是否已经存在自定义对象?

swift - 当没有字符串时,将 KILabel 或 ActiveLabel 的高度设置为 0。但 Original UILabel 工作正常