2012-09-07 25 views
1

我需要一些幫助與UITableView。我正在尋找創建編輯表功能的最佳解決方案。我的UITableViewController數據和兩種模式:編輯動畫UITableViewStyle像地址簿

  • 編輯模式:所有字段(如名字,姓氏,電話,網頁等)
  • 顯示模式:只顯示申請行。

困難的是當用戶點擊編輯按鈕時動畫行。

我想我們已經在iPhone上的地址簿應用程序相同的動畫。

回答

0

我有解決方案! Help from this article

所以你需要添加這樣的事情(感謝桑迪)

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{ 
    [super setEditing:editing animated:animated]; 
    NSArray *paths = [NSArray arrayWithObject: 
         [NSIndexPath indexPathForRow:1 inSection:0]]; 
    if (editing) { 

     [[self tableView] insertRowsAtIndexPaths:paths 
           withRowAnimation:UITableViewRowAnimationTop]; 
    }else { 
     [[self tableView] deleteRowsAtIndexPaths:paths 
           withRowAnimation:UITableViewRowAnimationTop]; 
    } 
} 

之後 - (NSInteger的)numberOfSectionsInTableView:(UITableView的*)的tableView - (NSInteger的)的tableView:(UITableView的*)的tableView numberOfRowsInSection:(NSInteger的)部分

將COLLED,您可以編輯細胞和它們的外觀的列表。

在下面的情況下
0

這樣簡單。

//original position and maybe hidden 
someView.frame = CGRect(0,0,0,0); 
someView.alpha = 0.0f; 
[someView setHidden:YES]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.3]; 

//what you want it comes out finally, changed position and visible 
[someView setHidden:NO]; 
someView.frame = CGRect(100.0f,100.0f,0,0); 
someView.alpha = 1.0f; 

[UIView commitAnimations]; 
+0

我沒有簡單的UIView。 我有表和大量的動態和不同的單元格 – Vladimir

0

使用

[tableView setEditing: YES animated: YES]; 

使的UITableView在編輯的時候,你刷卡的row.if你的動畫是什麼,請讓我知道mode.Which給你顯示和隱藏的按鈕。

+0

好吧,我如何添加新行沒有刷新表? – Vladimir

+0

是上面的ans有幫助嗎?我認爲你需要在添加它後重新加載表。 – Sandy

0

,我有2個部分,第一部分包含了一系列的設置,第一行是默認設置,總是存在的,不能被重新排序,而第二個只包含一個行像「添加.. 。',編輯僅用於在編輯模式下重新排序和刪除,所以我刪除第一個設置,並刪除第二個部分,並且如果您在tableview的beginUpdates/endUpdates中將您所有的插入/刪除操作放在一起,它就會流暢地動畫。因此,對於您編輯

在正常模式下它會適得其反,增加更多的行/段,我有:

Countries   (<-- 1st section) 
    - World 
    - Argentina 
    - USA 
         (<-- 2nd section) 
    - Add Countries... 

在編輯模式下,我有:

Countries   (<-- 1st section) 
    - Argentina = (can be removed/reordered) 
    - USA   = (can be removed/reordered) 

代碼看起來像:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 

    NSArray *paths = [NSArray arrayWithObjects: 
         [NSIndexPath indexPathForRow:0 inSection:0], 
         nil]; 
    [self.tableView beginUpdates]; // Club all updates together 
    if (editing) 
    { 
     if([[CCPollSettings countryCodes] count] < 2) // No country setting 
      // Remove complete section 
      [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 
     else // Remove first default row 
      [self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade]; 
     // Remove 'Add...' Section 
     [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; 
     // .... Do more stuff after 
    } else { 
     if([[CCPollSettings countryCodes] count] < 2) // No country setting yet 
      [self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 
     else // add back default row 
      [self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade]; 
     // Add back 'Add...' Section 
     [self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
    [self.tableView endUpdates]; // Club all updates together 
}