iphone - 如何从包含特定键的NSmutablearray中删除所有字典?

标签 iphone ios ipad

我有一个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/

相关文章:

iphone - Tableview滚动不是那么流畅?

ios - 如何在 iPhone 上的 Watch 设置应用中本地化 Watch OS 2 应用名称

iphone - 使用 uiwebview 创建一个富文本 uitableviewcell

ios - 获取粗体属性文本的 uilabel 高度

iOS:如何在 Settings.app 中显示可以删除的文件?

ios - 自定义过渡动画在关闭时不调用 VC 生命周期方法

ios - 使用导航呈现自定义大小的 View Controller

iphone - 如何在 Xcode 中管理屏幕方向?

iOS 上的 JavaScript : opening an HTML select element

ios - iPhone 和 iPad 上的缓存行大小是多少?