【发布时间】:2014-05-28 16:36:21
【问题描述】:
所以,我有一个描述多种美食的 plist。在我的 plist 中,我有 26 个数组,每个数组都有一个字母键。在这些数组中,包含多个美食,它们是字典。在每个字典中有 2 个字符串,一个是菜的名称,另一个是菜的描述。我非常接近在表格视图控制器中实现这一点,但我遇到了一些问题。主要问题是访问名称并将其放入一个数组中,以便可以使用它来判断每个部分中有多少行,该部分是字母表中的每个字母。我不断收到错误消息:"-[_NSArrayI length]: unrecognized selector sent to instance...
非常感谢您的帮助。谢谢
这就是我所拥有的:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView.tag == 1){
NSString *key = keys[section]; //returns the key(letter) for the section
NSDictionary *content = cuisines[key]; //returns the dictionary that consists of name and description
NSString *name = [content valueForKey:@"name"];
NSMutableArray *keyValues = [@[] mutableCopy];
[keyValues addObject:name];
return [keyValues count];
}else{
return [filteredcuisines count];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView.tag == 1) {
return [keys count]; //Return the amount of letters for the number of sections
}else{
return 1;
}
还有一张我的字典的图片: http://imageshack.com/a/img835/9567/kkv7.png
这是我的搜索条形码。我需要合并我对 plist 所做的更改。
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
[filteredcuisines removeAllObjects];
if (searchString.length>0) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@", self.searchBar.text];
for (NSString *key in keys) {
NSArray *matches = [cuisines[key] filteredArrayUsingPredicate:predicate];
[filteredcuisines addObjectsFromArray:matches];
}
}
return YES;
}
【问题讨论】:
-
filtered cuisines 是用户键入要搜索的内容时搜索栏的过滤后的美食字典
-
您的钥匙和美食中有什么。它们都是数组吗?
-
哦,对不起,美食是包含一切的字典。 keys 是一个由字母 A-Z 组成的数组。每个字母都是一个数组,可以容纳多个字典,每个字典都可以代表一种美食。每个字典美食都有一个名称和描述。
-
你能发布 numberOfSections 方法吗?
-
另外,如果 tableView.tag==1,你似乎总是返回 1。总是 keyValues 将有一个对象。如果是这样,为什么需要所有这些操作?
标签: objective-c xcode uitableview ios7 plist