iphone - 折叠 UITableView

标签 iphone objective-c ios uitableview

大家好,我在我的应用程序中制作了一个 UITableView,当一个单元格被触摸时,它扩大了我遇到的问题,无论我尝试了什么,它都不会崩溃,我确信它很简单,我就是想不通它唯一一次崩溃是在另一个单元格被点击时。

这是我的代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    selectedCellIndexPath = indexPath;

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];

    if (selectedCellIndexPath) {
        selected = YES;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{        
    if(selectedCellIndexPath != nil  
       && [selectedCellIndexPath compare:indexPath] == NSOrderedSame)  
        return 150;

    return 44;
}

最佳答案

您永远不会将 selectedCellIndexPath 更改为 nil,因此在选择新行之前不会更改当前选定的行。在 didSelectRowAtIndexPath 中,您应该将开头更改为以下内容:

if (selectedCellIndexPath == indexPath)
  selectedCellIndexPath = nil;
else
  selectedCellIndexPath = indexPath;

关于iphone - 折叠 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11128257/

相关文章:

Android、IOS 和 phonegap

ios - swift tableview 重新加载数据问题 - 自定义单元格中缺少元素

iphone - UIView 动画在 View 消失时停止,在重新出现时不会恢复

ios - 以编程方式在 Twitter 中获取 "Allow these Apps to use your account"的值

iphone - 如何从地址簿中检索 10-10 个联系人

ios - XCUITest 和 UIActivityViewController

android - Windows 上的 Meteor JS,支持 iOS 和 Android

iphone - iOS获取用户信息

objective-c - 反转 BOOL

ios - HealthKit 授权状态始终为 1