アニメーションを行さえできる方法を見つけ、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メソッドであるため、どれだけ長く機能するかを単純に知ることはできません。