2012-05-20 35 views
0

就像iPhone「設置」應用程序中的「Wi-Fi」,我有一個表格視圖,第一部分中的開關切換是否顯示以下部分。刪除多個表格視圖部分與每個部分的個人動畫

更新tableView: numberOfRowsInSection:後,我通過使用insertSections: withRowAnimation:deleteSections: withRowAnimation:成功了它。但是,與「設置」中的「Wi-Fi」不同,所有已刪除的部分在消失之前一起摺疊,

我想實現在「無線網絡連接」,在自己內部分崩單獨當他們從視圖中刪除同樣的效果。

建議如何做到這一點?

+1

你不只是在談論改變行動畫?也許像'UITableViewRowAnimationTop'? –

+0

嗨大衛,我試過所有的動畫風格。他們都將部分合並在一起,而不是單獨部分。此外,'UITableViewRowAnimationFade'是唯一一個在摺疊後淡出這些部分的人。 – James

+0

如果批處理動畫([myTableView beginUpdates];和[myTableView removeUpdates];)之間會發生什麼情況?使用合適的行動畫刪除所有行,並使用... RowAnimationFade? –

回答

0

我能夠做到這一點調用deleteSections每節:

static int nos = 4; 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return nos; 
} 

-(IBAction)onFadeTableButton:(id)sender 
{ 
    NSMutableIndexSet *sectionsToDelete = [NSMutableIndexSet indexSet]; 
    [sectionsToDelete addIndex:3]; 

    nos = 3; 
    [self.tableView deleteSections:sectionsToDelete 
        withRowAnimation:UITableViewRowAnimationTop]; 

    [sectionsToDelete addIndex:2]; 
    [sectionsToDelete removeIndex:3]; 
    nos = 2; 
    [self.tableView deleteSections:sectionsToDelete 
        withRowAnimation:UITableViewRowAnimationMiddle]; 


    [sectionsToDelete addIndex:1]; 
    [sectionsToDelete removeIndex:2]; 
    nos = 1; 
    [self.tableView deleteSections:sectionsToDelete 
        withRowAnimation:UITableViewRowAnimationMiddle]; 

    [sectionsToDelete addIndex:0]; 
    [sectionsToDelete removeIndex:1]; 
    nos = 0; 
    [self.tableView deleteSections:sectionsToDelete 
        withRowAnimation:UITableViewRowAnimationMiddle]; 

} 

的代碼是醜陋的,因爲我很快就使用現有項目(含4節表視圖),但這個想法必須明確。請勿按原樣使用它,請使它美觀。

+0

是的,我想我可能最終不得不在多個步驟中更新表視圖數據源,並刪除彼此成功的部分。如果有更簡單的方法來獲得效果,我仍然很好奇,所以我現在就把問題保持開放。感謝您的回覆,如果沒有更好的解決方案,我會接受您的回答。 – James

+0

@詹姆斯沒有問題,一個音符 - 與該代碼的部分同時刪除(好吧,必須有一個滯後,但在視覺上他們 - 下一個動畫不會等到前一個完成),如在Wi - Fi應用程序。對於需要隱藏/顯示某些東西的情況,我更喜歡使用額外的標誌數據源而不是重新分配具有數據的數據源 - 這爲我節省了大量時間,但這取決於您。 –

+0

你能詳細說明一下你的意思嗎?再次感謝。 – James

相關問題