insertRowsAtIndexPathsでセルが挿入されない
現在スイッチを押すとTableViewのセルを一行挿入する処理を行おうとしているのですが、下記のコードだと挿入されません。
試しにifを抜けた後に[self.tableView reloadData];を入れて実行すると、スイッチを押した後にセルが挿入されるようになるのですが、アニメーションもなくてカクカクした動きになっています。なのでinsertRowsAtIndexPathsを使ってセルの挿入を行いたいのですが、なぜ挿入されないのでしょうか?reloadDataが実行されるとセルが挿入されるということは、挿入の処理は正しく行えており、アニメーションがうまく行えていないということなのでしょうか...?
どなたか分かる方がいれば教えていただきたいです。すみませんが、よろしくお願いします。
if (sw.on) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1];
[identifierInSection2 addObject:@"pickerCell"];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
[identifierInSection2 removeLastObject];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}