我已經找到一種方法,讓你連排的動畫,並正在努力在iOS 8.3。所有你需要的是落實的tableView:numberOfRowsInSection:數據源的方法,然後添加/由UITableView的方法刪除行 insertRowsAtIndexPaths:withRowAnimation:和deleteRowsAtIndexPaths:withRowAnimation:。
下面是示例隱藏基於確切行UISwitch的狀態:
- (IBAction)alowNotif:(id)sender {
UISwitch *sw = (UISwitch*)sender;
NSIndexPath *index = [NSIndexPath indexPathForRow:5 inSection:0];
if ([sw isOn]) {
[self.tableView insertRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationAutomatic];
}
else {
[self.tableView deleteRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (![notifications isOn]) {
return 5;
}
return 6;
}
正如由@algal,numberOfRowInSection如上所述:仍然是UITableViewDataSource方法,因此一個不只是知道它會工作多久。
很高興您對此進行了排序,我對我的舊「答案」不工作感到內疚! – jrturton
這可能有效,但我認爲它不被支持,因爲Apple的Table View Programming Guid說:「如果故事板中的表視圖是靜態的,那麼包含表視圖的UITableViewController的自定義子類不應該實現數據源協議。」 (來自https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/CreateConfigureTableView/CreateConfigureTableView.html#//apple_ref/doc/uid/TP40007451-CH6-SW27)。這些方法全部來自數據源協議。換句話說,當Apple升級產品時,不能保證這個解決方案不會中斷。 – algal
這似乎在iOS 8中失敗。控制檯吐出一個警告,該委託實現了靜態表視圖,這可能是錯誤的,它會忽略委託。謝謝,蘋果! – osxdirk