2013-01-10 154 views
1

我使用的是UITableView靜態細胞我的應用程序的設置視圖。毛刺動畫時與靜態細胞

一個該表的部分都包含兩個小區,第二個僅當包含在第一個的UISwitch被接通是可見的。

所以UISwitch的目標是:

- (void)notificationSwitchChanged:(id)sender 
{ 
    UISwitch* switch = (UISwitch*)sender; 

    self.bNotify = switch.on; 
    [self.settingsTable reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop]; 
} 

我實現numberOfRowsInSection:這樣:

(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section != 1) 
    return [super tableView:tableView numberOfRowsInSection:section]; 

    if (self.bNotify) 
    return 2; 
    return 1; 
} 

這個 「作品」,但動畫發生故障,使得第一個單元格消失或根據我選擇的動畫類型,向上滑動到上一部分下方或各種東西的上方。最乾淨的是UITableViewRowAnimationNone,但仍不完美。

如果我滾動部分拿出來看並支持它看起來恢復正常。

編輯:把問題的幾張截圖:
Example Image

我嘗試過和reloadSections後加入beginUpdatesendUpdates但它並沒有改變任何東西。使用reloadData而不是reloadSections作品,但根本沒有動畫。

是因爲表的單元格是靜態的還是我失去了一些東西?

+0

嘗試'[self.tableView setNeedsLayout];'。 –

+0

我嘗試在'reloadSections'後面添加它,沒有任何效果。 – Jukurrpa

回答

1

我覺得這個方法應該解決您的問題。

[self.tableView insertSections:<#(NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>]; 

只需更新數據源(你沒有,因爲你正在更新取決於一些標誌區段計數),並調用它。

也許你就必須使用這個方法來代替。

[self.tableView insertRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>]; 
+0

使用'insertRowsAtIndexPaths'是解決方案,這種方式沒有更多的小故障。謝謝。 – Jukurrpa