【问题标题】:filter an NSArray, which contains NSDictionary within NSDictionary过滤一个 NSArray,它在 NSDictionary 中包含 NSDictionary
【发布时间】:2012-10-11 17:04:50
【问题描述】:

我正在尝试过滤包含NSDictionary 对象的NSArray。这个NSDictionary 再次在其中包含NSDictionary

看起来像这样。

[
  {
    Comp_Name =      {
        text = "Quality Ace #5846-C";
    };
    ShipTo =         {
        text = 312025846;
    };
    SoldTo =         {
        text = 10000081;
    };
  },
  {
    Comp_Name =      {
        text = "Billington Ace Hardware  - 5863K";
    };
    ShipTo =         {
        text = 312025863;
    };
    SoldTo =         {
        text = 10000081;
    };
  }
]

我想将此数组过滤为一些与“Comp_Name”对象匹配的“文本”。

我使用的代码是:

_filteredList = [_unFilteredArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"Comp_Name == %@", searchBar.text]];

请帮助我获取基于对象“Comp_Name”、“text”的过滤列表。

【问题讨论】:

  • 谓词不应该是@"Comp_Name.text == %@"吗?
  • 我也试过了。似乎没有工作。结果我得到一个空数组。
  • 也许是字符串周围缺少引号。使用@"Comp_Name.text == '%@'"。
  • 知道了....我使用的是@"Comp_Name.text" == %@" 而不是@"Comp_Name.text contains[cd] %@"。第二个对我有用。谢谢大量的帮助。
  • 您的问题是“匹配”,而不是“包含”。

标签: objective-c ios nsarray nsdictionary


【解决方案1】:

@rmaddy - 感谢您的帮助!!! @"Comp_Name.text == %@" 工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    相关资源
    最近更新 更多