2012-08-06 36 views
1

我试图在UITableviewCells上实施轻扫手势,因此当用户向右滑动时,我希望细胞移动到具有动画效果的表格底部(就像iphone中的CLEAR应用程序)。我已经提到这个链接http://www.cocoacontrols.com/platforms/ios/controls/jtgesturebasedtableviewdemo,并试图实现它。下面是我的代码,我至今当状态是“正确的”将细胞移动到UITableView底部时,用动画效果向右滑动

- (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]; 
} 

所以你可以看到当国家是正确的,我想实现它,但我不理解如何有一个动画尝试影响。所以朋友们,我请求通过此代码并帮助我。

问候 兰吉特

+0

您好朋友,有什么建议吗? – Ranjit 2012-08-07 06:49:42

回答

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]; 
} 
0

UITableView管理其自身细胞的布局。

可以完成你想要的方式:

  1. ...明智地告诉表视图不是动画受影响的细胞,创建副本视图层次和动画的意见,然后显示在其表结束状态。 - 或 -

  2. ...继承表视图并重新实现其动画逻辑。 - 或 -

  3. ...创建您自己的表格视图。

+0

感谢您的回复,在“正确的状态”中的代码是什么 – Ranjit 2012-08-07 07:49:38

+0

我不明白你的意思。 – Jesper 2012-08-07 09:38:01

+0

我的意思是我在state = right时编写的代码,将单元格移动到表底部,我想知道它是否正确 – Ranjit 2012-08-07 09:39:25