我有一个iPhone应用程序,其中有字典的NSMutableArray
。当选择表格的每一行时,我通过使用以下方式删除字典
if (indexPath.row <[self.newmessagearrays count])
{
[messagearrays removeObjectAtIndex:indexPath.row];
}
我有一种情况,当点击该行时,我想删除所有我的“from id”键相同的字典。我这样尝试过,但没有效果:
NSPredicate * pr = [NSPredicate predicateWithFormat:@"userid == %@",fromidstring];
[messagearrays filterUsingPredicate:pr];
最佳答案
您可以使用NSPredicate
在适当的位置过滤数组:
NSPredicate * pr = [NSPredicate predicateWithFormat:@"containsKey == SOME_KEY"];
[messageArrays filterUsingPredicate:pr];
更新
针对编辑/说明:
NSPredicate * pr = [NSPredicate predicateWithBlock:
^(id dictionary, NSDictionary * bindings) {
return (BOOL)![[dictionary objectForKey:@"fromid"] isEqual:@"190"];
}];
[messageArrays filterUsingPredicate:pr];
关于iphone - 如何从包含特定键的NSmutablearray中删除所有字典?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15106461/