2012-08-06 34 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