views:

2905

answers:

1

I need delete row 1 of a table in a function i have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defined. How can I create an indexpath like this?

An array with the int {1} as it's only member will crash; the nslog message states that the section needs to be defined as well.

*Edit -> Code relating to cell delete:

    NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
    NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
//  [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
//  [self.tableView endUpdates];
+5  A: 

Use [NSIndexPath indexPathForRow:inSection:] to quickly create an index path.

Ben Gottlieb
Thanks for the reply. The program still crashes though -- NSLog reports: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSIndexPath indexPathForRow:inSection:]: unrecognized selector sent to instance
Vurk
please show your source code.
Ben Gottlieb
I originally figured it to be an IndexPath problem. Is there something else going on? Seems i might be using the delete incorrectly..
Vurk
-[NSIndexPath indexPathForRow:inSection:] isn't in my documentation. Is there an answer that uses documented APIs?(I admit it's a bit weird that it's not in there. WTH?!)
Olie
Found my answer at http://stackoverflow.com/questions/181432/how-to-create-the-indexes-required-for-nsindexpathindexpathwithindexeslength -- it's "documented" in UITableView.h
Olie