大家好,我在我的应用程序中制作了一个 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/