0
votes

I have a table which I am manipulating with a tableViewController (no nib, and the controller is creating the table behind the scenes) I'm trying to delete a row from the table based on its row number; I can delete it from the array I use to create the cell in cellForRowAtIndexPath, but I get a strange error if I try to do the following, which is the same code as in tableView:commitEditingStyle:forRowAtIndexPath: where it works fine

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i+1 inSection:1]

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

It gives an error

-[_WebSafeForwarder forwardInvocation:]

and then jumps out of the method but does not crash the app

Can anyone help?

2

2 Answers

0
votes

You need to do that in this block.

[self.tableView beginUpdates];

///

[self.tableView endUpdates];

do notice one thing that when the the block reaches its end

- (void) numberOfRowsInSection:(NSInteger)section

will be called again. so u need to update the number of rows in table view also.

Hope this helps.

Thanks,

Madhup

-1
votes

Well you are missing a semi-colon on your first line.

When in doubt, clean up your syntax...

As a point of observation, most of the programmers I have worked with and talked to really hate UITableViewController. It really adds nothing to the functionality for the user and only obfuscates things that developers might really like to control... such as the position of the table via a XIB.

It's just a convenience class and in my experience, causes more issues than it prevents.