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 に答える