2013-01-10 157 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