1

我正在尝试在 UITableviewCells 上实现滑动手势,所以当用户向右滑动时,我希望单元格移动到具有动画效果的表格底部(就像 iphone 中的 CLEAR 应用程序一样)。我已经提到了这个链接 http://www.cocoacontrols.com/platforms/ios/controls/jtgesturebasedtableviewdemo,并试图实现它。以下是我到目前为止在状态“正确”时尝试过的代码

- (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer commitEditingState:(JTTableViewCellEditingState)state forRowAtIndexPath:(NSIndexPath *)indexPath 
  {
    UITableView *tableView = gestureRecognizer.tableView;

    [tableView beginUpdates];

    if (state == JTTableViewCellEditingStateLeft) 
    {
        // An example to discard the cell at JTTableViewCellEditingStateLeft
        [self.rows removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
    else if (state == JTTableViewCellEditingStateRight)
    {       

        ***NSString *selectedString = [self.rows objectAtIndex:indexPath.row];     

        [self.rows removeObjectAtIndex:indexPath.row];
        //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
        //                 withRowAnimation:UITableViewRowAnimationLeft]; 

       NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];

       [tableView moveRowAtIndexPath:selectedIndexPath toIndexPath:[NSIndexPath        indexPathForRow:[self.rows count]-1 inSection:0]];          

        [self.rows insertObject:selectedString atIndex:[self.rows count]];        
        [tableView insertRowsAtIndexPaths:[NSArray
                                           arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]]
                         withRowAnimation:UITableViewRowAnimationBottom];

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];*** 
    } 

    [tableView endUpdates];

    // Row color needs update after datasource changes, reload it.
    [tableView performSelector:@selector(reloadVisibleRowsExceptIndexPath:) withObject:indexPath afterDelay:JTTableViewRowAnimationDuration];
}

因此,您可以看到状态何时正确,我正在尝试实现它,但我不了解如何产生动画效果。所以朋友们,我请求请通过此代码并帮助我。

问候兰吉特

4

2 回答 2

0
于 2012-08-07T07:37:31.480 回答
0

我对此进行了研究并提出了这个解决方案,现在当我向右滑动单元格并且单元格移动到底部时,我得到了效果,但是我的单元格没有更新,每当我向右滑动单元格时,它需要字符串位于其下方位置的单元格。无法理解我错过了什么

- (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer commitEditingState:(JTTableViewCellEditingState)state forRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableView *tableView = gestureRecognizer.tableView;
    [tableView beginUpdates];
     if (state == JTTableViewCellEditingStateRight)
    {

        NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];

        [tableView moveRowAtIndexPath:selectedIndexPath toIndexPath:[NSIndexPath indexPathForRow:[self.rows count]-1 inSection:0]];          

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; 
    } 

    [tableView endUpdates];

    // Row color needs update after datasource changes, reload it.
    [tableView performSelector:@selector(reloadVisibleRowsExceptIndexPath:) withObject:indexPath afterDelay:JTTableViewRowAnimationDuration];
}



-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{

    NSString *selectedString = [self.rows objectAtIndex:sourceIndexPath.row];     

    [self.rows removeObjectAtIndex:sourceIndexPath.row];

    [self.rows insertObject:selectedString atIndex:[self.rows count]-1]; 
}
于 2012-08-08T07:10:26.803 回答