我很难搞清楚为什么我的UITableViewCell在取消选中时不会为contentView设置动画。
我已经制作了一些扩展和折叠单元格的代码,但是在以某种方式折叠单元格时,它会为高度设置动画,但不会为contentView设置动画。实际上似乎删除了contentView。
为了记录,我在内容视图中添加了UILabel。当扩展时,UILabel的框架将相应地调整大小,但是当折叠UILabel时,只是在没有动画的情况下被解散或隐藏。
有什么建议吗?
以下是一些示例代码:
/* Expanding and collapsing code */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath])
{
//Item is clicked, unclick it
[self.selectedIndexes removeObject:indexPath];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
else
{
//Item is not clicked. Deselect others and select this
[self.selectedIndexes removeAllObjects];
[self.selectedIndexes addObject:indexPath];
}
[tableView beginUpdates];
[tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([self cellIsSelected:indexPath]) {
return 150;
}
return [tableView rowHeight];
}
答案 0 :(得分:0)
试试这个,希望它有所帮助
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(add == NO)// i took bool to compare change it for your need
{
[self.aTableVIew deselectRowAtIndexPath:indexPath animated:YES];
//you need do deletions witin this commit and begin
[self.aTableVIew beginUpdates];
//animations are within beginUpdates and endUpdates otherwise no animations
[array removeObjectAtIndex:indexPath.row];
[self.aTableVIew deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.aTableVIew endUpdates];
add = YES;
}
else
{
//else in your case add objects to array and reload the table
[array removeAllObjects];
[self.aTableVIew reloadData];
[self.aTableVIew beginUpdates];
//compute where to insert
[array addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
[self.aTableVIew insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
[self.aTableVIew endUpdates];
add = NO;
}
}
答案 1 :(得分:0)