i have this code for deleting the cell content from database
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[appDelegate.indexArray removeObjectAtIndex:indexPath.section];
[appDelegate.notesArray removeObjectAtIndex:indexPath.section];
[tableViewObj reloadData];
NSString *DataPath = [MyBibleAppAppDelegate getPath];
[appDelegate.data writeToFile:DataPath atomically:YES];
[tableViewObj reloadData];
}
}
it works perfect but i need to put the above code in my button click ,i put this in button click
-(IBAction)_clickbtndeltNoteall:(id)sender
{
[appDelegate.indexArray removeObjectAtIndex:indexPath.section];
[appDelegate.notesArray removeObjectAtIndex:indexPath.section];
[tableViewObj reloadData];
NSString *DataPath = [MyBibleAppAppDelegate getPath];
[appDelegate.data writeToFile:DataPath atomically:YES];
[tableViewObj reloadData];
}
But I got this error: “Undeclared identifier indexpath”. How to solve this?
I suggest saving the indexPath for the pressed row in a singleton. Here is a guide on how to use the singleton class to store objects and use them across classes.
In this example you can also just declare an instance variable and set it when the row is pressed in the appropriate delegate method for your UITableView. This could be done like so:
Your action for your button should now look like this:
The code for the button assumes that a row have been selected before it is pressed. You could also initialize your indexPath in the viewDidLoad
like so:
You should adjust your initialization to what would be appropriate for your specific program!