我正在尝试将搜索图像(放大镜)添加为部分,以便轻松转到搜索栏。
这是我遇到的问题:
我设置这些部分的代码如下:
注意:self.fbFriends 是一个字典数组,其中包括用户的 facebook 好友。
self.fbFriends = [[NSArray alloc] initWithArray:[[MESCache sharedCache] facebookFriends]];
self.searchResults = [[NSMutableArray alloc] init];
self.sections = [[NSMutableDictionary alloc] init];
BOOL found;
[self.sections setValue:[[NSMutableArray alloc] init] forKey:UITableViewIndexSearch];
// Loop through the friends and create our keys
for (NSDictionary *friend in self.fbFriends)
{
NSString *c = [[friend objectForKey:@"name"] substringToIndex:1];
found = NO;
for (NSString *str in [self.sections allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
if (!found)
{
[self.sections setValue:[[NSMutableArray alloc] init] forKey:c];
}
}
// Loop again and sort the friends into their respective keys
for (NSDictionary *friend in self.fbFriends)
{
[[self.sections objectForKey:[[friend objectForKey:@"name"] substringToIndex:1]] addObject:friend];
}
// Sort each section array
for (NSString *key in [self.sections allKeys])
{
[[self.sections objectForKey:key] sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]];
}
这是我的部分设置和标题视图:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return 1;
} else {
return [[self.sections allKeys] count];
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return NSLocalizedString(@"FbFriendsSearchControllerSection", @"Fb Friends search controller - section title for search results table view");
} else {
return [[[self.sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:section];
}
}
有谁看到这是不正确的?