2012-04-04 160 views
0

我被这个难住了:我测试了我的应用程序在iPhone模拟器4.3和5.0中的过滤功能,一切正常,但在iPhone上,谓词让我错误的结果。 (我怀疑它是与正则表达式,但我没有看到一个错误。)在模拟器上工作的代码,但不在iPhone上?

if (!selectionDidChange) 
    return; 
[matches release]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"meta LIKE[c] %@", 
          UniversalKeyword]; 
NSPredicate *regional = [NSPredicate predicateWithFormat:@"regional == NIL OR regional == NO OR " 
         @"(regional == YES AND title.%K != NIL)", CurrentLanguage]; 
NSPredicate *exclusive = (exclusiveUpgrade ? [NSPredicate predicateWithValue:YES] : 
          [NSPredicate predicateWithFormat:@"exclusive == NIL OR exclusive == NO"]); 
NSMutableArray *predicates = [[[NSMutableArray alloc] initWithCapacity:5] autorelease]; 
for (int i = 0; i < L(keywords); i++) 
{ 
    int selection = [D(A(keywords, i), @"selection") intValue]; 
    if (selection >= 0) 
     A_ADD(predicates, ([NSPredicate predicateWithFormat:@"meta MATCHES[c] %@", 
          S(S(@".*\\b", D(A(D(A(keywords, i), @"values"), selection), @"name")), @"\\b.*")])); 
} 
NSPredicate *compound = [NSCompoundPredicate andPredicateWithSubpredicates:predicates]; 
[predicates removeAllObjects]; 
[predicates addObject:predicate]; 
[predicates addObject:compound]; 
predicate = [NSCompoundPredicate andPredicateWithSubpredicates:A_NEW(regional, exclusive, 
      [NSCompoundPredicate orPredicateWithSubpredicates:predicates])]; 
matches = [[entries filteredArrayUsingPredicate:predicate] retain]; 
selectionDidChange = NO; 

对于澄清:

  • entrieskeywords是字典的数组,虽然keywords有点复杂。重要的是,entries中的每个字典都包含一个名为meta的字符串,它可以看起来像这样:“A,B,C,D”。如果用户搜索“C”,那么正则表达式应该匹配。还有其他的标准似乎不是问题,因为我检查了编译后的谓词,它看起来很好。
  • 我应该提一下,谓词的第一部分(meta LIKE[c] %@)也给我iPhone上的预期结果。
  • 我在这里有一些使用方便的宏:A_ADD = addObject:,D = objectForKey:,A = objectAtIndex:,A_NEW = arrayWithObjects:,L = countS = stringByAppendingString:。 (是的,我很懒:D)​​

我在这里忽略了什么?

+2

模拟器中的某些项目不区分大小写。即“@ 2x”和“@ 2X”都将在模拟器中显示视网膜图像,但不是该设备。确保你传递的大写字母是你期望的。 – jmstone617 2012-04-04 13:48:58

+0

感谢您的提示,这是很好的知道。但是,我仔细观察了NSLog输出,发现我的设备上的应用程序从过时的缓存文件中提取数据;我应该先删除应用程序,而且谓词可以正常工作。它可以是那么容易... – vbwx 2012-04-04 17:03:19

+1

很高兴你明白了。要么提供答案,要么标记这只小狗关闭:) – jmstone617 2012-04-04 17:05:53

回答

1

以下是任何人的情况下的关键点别的有类似的问题:

  1. NSPredicate之间在iPhone和在iOS模拟器相应的执行没有功能上的差别。
  2. 如果您的应用在实际设备上的表现与模拟器上的行为不同,请仔细检查文件名和其他字符串是否需要大小写,如jmstone表示。
  3. 如果问题仍然存在,请从模拟器和设备中删除应用程序。 Xcode有许多自动行为,但它不会清理模拟器或设备上的任何内容。
相关问题