我试图在数组中找到选定的人员。我正确地找到没有人被选中的位置,但是,如果选择了一个组中的一个人,则会选择该组中的所有人。尝试识别选定的表格视图单元格
经过长时间的头部划伤会话后,我可以使用一些帮助来查看是否有明显的东西。
该动作在cellForRowAtIndexPath
正在进行这样的:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
static NSString *pCell = @"Cell";
PeopleCell *cell = (PeopleCell *)[aTableView dequeueReusableCellWithIdentifier:pCell];
if (cell == nil) {
cell = [[PeopleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pCell];
}
people = [peopleArray objectAtIndex:[indexPath row]];
NSString *text = [people objectForKey:@"name"];
cell.textLabel.text = text;
if (selectedPeopleinGroup.count == 0) {
//no people selected in this group
NSLog(@"none");
cell.isSelected = [selectedPeopleinGroup containsObject:text] == NO;
} else {
//there are some people in this group - find out who they are
NSLog(@"some");
NSString *key1 = [selectedPeopleinGroup valueForKey:@"personKey"];
NSString *key2 = [people valueForKey:@"personKey"];
NSLog (@"key1 %@", key1);
NSLog (@"key2 %@", key2);
if (key1 == key2) {
cell.isSelected = [selectedPeople containsObject:text] == YES;
} else {
cell.isSelected = [selectedPeople containsObject:text] == NO;
}
}
return cell;
}
所述细胞是子类的UITableViewCell具有如果选定的单元格的左边侧上的复选标记图像和不同的图像,如果不选。非常感谢。
'selectedPeopleInGroup'。这是一个数组还是字典? – Abizern
这是一个NSArray。 –