I have dynamic tableView with custom cells in it, i want to delete some cell if its value is 0, for example.
Here's my tableView:cellForRowAtIndexPath
method:
{
NSString *CellIdentifier;
UITableViewCell *cell;
if (indexPath.row == 0){
CellIdentifier = @"adress cell";
CustomAdressCell *cell = [detailsTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomTimeCell" owner:self options:nil];
cell = [objects lastObject];
}
cell.someValue = self.someVal;
return cell;
}
else if (indexPath.row == 1){
CellIdentifier = @"phone cell";
CustomPhoneCell *cell = [detailsTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomPhoneCell" owner:self options:nil];
cell = [objects lastObject];
}
indexPathTest = indexPath;//index path for delete
cell.someValue = self.someVal2;
return cell;
}
...
else return cell;
}
For example: if i have cell.someValue = 0
on second row, i need to delete this row. How can i achieve this? Thanks!
EDIT: i'm trying to delete rows after i initialised my tableView in another VC with the following code(custom method):
[self.detailsTableView beginUpdates];
[self.detailsTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathTest]
withRowAnimation:UITableViewRowAnimationFade];
[self.detailsTableView endUpdates];
And i'm having error:
Invalid update: invalid number of rows in section 0. The number of rows contained in an
existing section after the update (4) must be equal to the number of rows contained in that
section before the update (4), plus or minus the number of rows inserted or deleted from that
section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that
section (0 moved in, 0 moved out).'
Some other questions that didn't helped me: