gpt4 book ai didi

iphone - 如何从 NSMutableDictionary 中删除字典数组?

转载 作者:行者123 更新时间:2023-11-28 20:20:52 25 4
gpt4 key购买 nike

我有数组字典(里面还有数组和字典)。

我在我的 UITableView 中添加了 UITableViewCellEditingStyleDelete,所以我想从字典中删除特定的字典数组。

数据的控制台 View :

{
A = (
{
address = "Talala (gir)";
"main_id" = 1;
mobile = 8878876884;
name = "Amit Patel";
},
{
address = "Junagdh";
"main_id" = 5;
mobile = 4894679865;
name = "Arjun Patel";
}
);
J = (
{
address = "Taveli";
"main_id" = 6;
mobile = 87886356085878;
name = "Jasmin Patel";
},
{
address = "Gujarat";
"main_id" = 4;
mobile = 6636633368;
name = "Jatin ";
}
);
R = (
{
address = "Mumbai";
"main_id" = 2;
mobile = 999686322;
name = "Rajan Patel";
}
);
S = (
{
address = "Rajkot";
"main_id" = 3;
mobile = 8866086549;
name = "Sumit Patel";
}
);
}

我想删除,例如:数组的索引是1,来自键为A的字典

我必须尝试使用​​以下代码

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{

NSDictionary *dic = [[self.finalPDic objectForKey:[self.listOfHeader objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];

NSLog(@"%@",dic);

[self.finalPDic removeObjectForKey:dic];

NSLog(@"%@",self.finalPDic);

[self.tblView reloadData];
}
if (editingStyle == UITableViewCellEditingStyleInsert)
{
}
}

但是我无法从主 NSMutableDictionary 中删除任何记录。

最佳答案

试试这个

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
NSString *key = self.listOfHeader[indexPath.section];

NSMutableArray *users = [self.finalPDic[key] mutableCopy];

[users removeObjectAtIndex:indexPath.row];
if (users){
self.finalDic[key] = users;
}else{
[self.finalDic removeObjectForKey:key];
}
[self.tblView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
if (editingStyle == UITableViewCellEditingStyleInsert){
}
}

关于iphone - 如何从 NSMutableDictionary 中删除字典数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16076913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com