배열에서 선택한 사람을 찾으려고합니다. 아무도 선택되지 않은 곳을 정확하게 알 수 있지만 그룹의 한 사람이 선택되면 그룹의 모든 사람이 선택됩니다.선택한 테이블보기 셀을 식별하려고합니다
긴 머리 스크래칭 세션 후, 나는 분명 도움이 될만한 도움이 될 것입니다.
이 작업은 다음과 같이 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입니다. –