I have a tableView, which initially has 4 sections with 1 row in each. Depending on the user interaction with the first row, I need to insert or delete a second row in the section. After that, I need to do the setup of the cell, which is next after tapped. Here's my code for handling interaction:
-(void) tableViewSwitchToggled: (UISwitch*) sender{
targetSection = sender.tag; //each switch is added to cell's contentview and it's tag is set to indexPath.section
UITableView* tableView = ...
if (someBool){
[tableView insertRowsAtIndexPaths: [NSArray arrayWithObject: [NSIndexPath indexPathForRow: 1 inSection: targetSection]] withRowAnimation: UITableViewRowAnimationTop];
UITableViewCell* detailsCell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: targetSection + 1]]; //I try to get the first row of the next section and it is always nil!!!
//do something with detailsCell content
}
else{
[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: [NSIndexPath indexPathForRow: 1 inSection: targetSection]] withRowAnimation: UITableViewRowAnimationRight];
UITableViewCell* detailsCell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: targetSection + 1]]; //and it works perfectly, giving me the cell address
//do something with detailsCell content
}
}
So here's my question - why do I get a nil cell after I insert a row? Isn't the tableView supposed to have all cells already allocated? Thanks for your help!