1

我正在搜索UITableView使用这个:

titles = [NSArray arrayWithArray:[datamanager titlesForEntriesBetween:(NSInteger)[slider minSelectedValue] and:(NSInteger)[slider maxSelectedValue]containing:searchText]];

如何NSASCIIStringEncoding在搜索过程中对数组值进行编码?

(数组包含"tête"例如..当我搜索"tete"不匹配时..所以我将为我的搜索编码数组值)

4

1 回答 1

1

我会将第三个参数添加到您的 datamanager 函数中:

- (NSArray*)titlesForEntriesBetween:(NSInteger)startIndex
  and:(NSInteger)stopIndex
  withFunction:(BOOL(^)(NSString*))block {
  NSMutableArray *retVal = [NSMutableArray array];
  for(NSInteger i = startIndex; i <= stopIndex; ++i) {
    NSString *string = [array_ objectAtIndex:i];
    if (block(string)) {
      [retVal insertObject:string];
    }
  }
  return retVal;
}

然后我会这样调用函数:

titles = [datamanager titlesForEntriesBetween:(NSInteger)[slider minSelectedValue] and:(NSInteger)[slider maxSelectedValue] withFunction:^(BOOL)(NSString *str) {
  NSData *data = [str dataUsingEncoding:NSASCIIStringEncoding];
  NSString *simpleString = [[[NSString alloc] initWithData:data usingEncoding: NSASCIIStringEncoding] autorelease];
  return [simpleString isEqualToString:str];
}]];

注意:我只是输入了这个,我没有尝试编译/运行它。

于 2012-11-20T15:21:17.290 回答