【问题标题】:iPhone SDK Noob Problem with Search Bar搜索栏的 iPhone SDK Noob 问题
【发布时间】:2010-10-21 19:32:49
【问题描述】:

希望你能回复这个:

我曾经有过这种数组:

NSArray *array = [NSArray arrayWithObjects:@"Object1", @"Object2", @"Object3", nil];
NSDictionary *arrayDictionaryDict = [NSDictionary dictionaryWithObject:array forKey:@"Key"];

[listOfItems addObject:arrayDictionaryDict];

现在我有了这个:

NSDictionary *dict1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Object1", @"Subtitle1", @"Object2", @"Subtitle2", @"Object3", @"Subtitle3", nil] forKeys:[NSArray arrayWithObjects:@"title", @"subtitle", @"title", @"subtitle", @"title", @"subtitle", nil]];

listOfItems = [[NSArray alloc] initWithObjects:dictA, nil];

我也有一个使用这种方法的搜索栏:

// in search the table view void
[…]
for (NSDictionary *dictionary in listOfItems) {

     NSArray *array = [dictionary objectForKey:@"Key"];
 [searchArray addObjectsFromArray:array];

}

[B]我应该如何更改最后一种方法以适应新的数组并在标题和副标题中搜索?[/B]

感谢

【问题讨论】:

  • 只是一个简短的旁注:NSDictionary 不能保存共享相同键的对象。 @"title" 键可以有一个对象,@"subtitle" 键可以有一个对象,但不能三个。
  • 我明白了。那么,我应该如何使用每个单元格的可搜索标题和副标题对表格视图进行分段?
  • 你可以创建一个 NSArray 来保存 NSDictionary,每个都有一个 @"title" 和 @"subtitle" 键
  • 什么意思?我无法想象。请你举个例子好吗?非常感谢。

标签: iphone uitableview uisearchbar


【解决方案1】:
NSArray *array = [dictionary allValues];

这将返回一个包含所有已保存值的 NSArray。如果我正确理解你的问题,这就是你要找的。​​p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多