【发布时间】:2012-03-20 09:08:20
【问题描述】:
在我的应用程序中,我无法从 tableview 中删除行。 tableview 的内容作为 web(GET) 响应出现,我在 tableview 中显示它,我在第二个视图控制器中显示它的一些详细信息(单击索引处的行时推送..)有人可以帮忙吗? 这是我的一些代码:(在 viewDidLoad 中)
sharedDa= (BNT_AppDelegate *)([[UIApplication sharedApplication]delegate]);
mm= [[sharedDa messagesDict]objectForKey:@"message"];//mm is NSDictionary
mm 包含一些属性(例如日期、消息..),我想我需要从字典中删除索引处的对象。我该如何处理这种情况?
EDIT-2: 这是我的 JSON 对象;
{
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";
}
);
}
这是我的初始化代码:
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"];
我解析了我的可变字典并用它初始化了不同的可变数组,这正是我删除行的委托方法;
- (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]; } }
我的应用程序崩溃,在控制台中我得到以下三行:
Thread: <NSThread: 0x75719d0>{name = (null), num = 1}
[Switching to process 1472 thread 0x10a03]
(gdb)
我知道这是一个很长的问题,但谁能给我一个想法?
【问题讨论】:
标签: ipad uitableview ios5 nsdictionary