In my app i can’t delete row from tableview. The content of the tableview comes as a web(GET) response and i display it in a tableview, i display some details of it in a second view controller(push when clickcing row at index..) Can someone help please?
Here is some of my codes:(in viewDidLoad)
sharedDa= (BNT_AppDelegate *)([[UIApplication sharedApplication]delegate]);
mm= [[sharedDa messagesDict]objectForKey:@"message"];//mm is NSDictionary
The mm contains a few properties(such as date, message..) and i think i need to delete object at index from Dictionary. How can i handle this situation?
EDIT-2:
Here is my JSON object;
{
button = 30;
message = (
{
date = "2012-03-21 20:13:10";
message = "message 1";
},
{
date = "2012-03-21 20:13:42";
message = "asdf nkop jp?l?f";
},
{
date = "2012-03-22 10:06:11";
message = "test local notification message";
},
{
date = "2012-03-22 10:06:41";
message = "second test of uilocalnotification";
},
{
date = "2012-03-22 10:08:13";
message = "third test of notification";
}
);
}
And here is my initializing code:
sharedDa= (BNT_AppDelegate *)([[UIApplication sharedApplication]delegate]);
//mm is mutableDictionary and the others are mutable array
mm= [[sharedDa messagesDict]objectForKey:@"message"];
// NSLog(@"JSON message: %@", [sharedDa messagesDict]);
buttonVersion= [sharedDa.messagesDict objectForKey:@"button"];
mySecondArray= [mm valueForKey:@"date"];
myIDsArray=[mm valueForKey:@"ID"];
I parsed my mutable dictionary and initialized different mutable arrays with it, here is exactly my delegate method to delete row;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
NSLog(@"Thread: %@", [NSThread currentThread]);
[self.myIDsArray removeObjectAtIndex:indexPath.row];
[self.myArray removeObjectAtIndex:indexPath.row];
[self.mySecondArray removeObjectAtIndex:indexPath.row];
[self.buttonVersion removeObjectAtIndex:indexPath.row];
//
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } }
My app crashes and in the console i get these three lines:
Thread: <NSThread: 0x75719d0>{name = (null), num = 1}
[Switching to process 1472 thread 0x10a03]
(gdb)
I know it became a very long question but can anyone give me an idea?
Firstly: name your variables a little readable,
mmlooks a little stupid.Let’s say you have three different objects in your dictionary, create three different
NSMutableArrays to hold these objects and in the implementation ofuse the method
removeObjectAtIndex:for all of your arrays.