细胞删除动画没有从didSelectRowAtIndexPath:



基本上,当您选择特定的行时,我希望表视图中的所有行都被删除。为此,我有以下代码:

-(void)removeRows:(int)i
{
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [_table cellForRowAtIndexPath:ip];
CGRect newFrame;
if(i%2==0){
    newFrame = cell.frame;
    newFrame.origin.x = -[UIScreen mainScreen].bounds.size.width;
}else{
    newFrame = cell.frame;
    newFrame.origin.x = [UIScreen mainScreen].bounds.size.width;
}
[UIView animateWithDuration:0.2 delay:0 options:0
                 animations:^{cell.frame = newFrame;}
                 completion: ^(BOOL finished){
                     if(i == 0){
                         [dataSource removeAllObjects];
                         [_homeScreenView.proustPacks reloadData];
                     }
}];  
}

按相反顺序对每一行调用此方法。现在一切都很好,如果我使用它为我的删除按钮(这不是tableView的一部分),但现在我想要相同的动画和动作,当用户点击一个特定的单元格,像:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([(Something*)[dataSource objectAtIndex:indexPath.row] isWhatIWant]){
    [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(remove) userInfo:nil repeats:NO];
    [NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(goToNext:) userInfo:nil repeats:NO];
}
}

其中"goToNext:"将下一个控制器推送到navigationController而removePacks是:

-(void)remove{
    int aux = _dataSource.count -1;
    for(int i=aux;i>=0;i--){
        [self removeRows:i];
}
} 

我想你可以这样回答:

https://stackoverflow.com/a/22085713/661749

基本上你需要把所有的索引路径给remove函数,然后选择你想要的动画。不要忘记更改您的集合

最新更新