섹션 및 다중 선택과 함께 tableview를 사용하고 있지만 하나의 행을 선택할 때 여러 행을 확인하는 데 문제가 있습니다 ... 이것에 대해 다른 스레드,하지만 정말 솔루션을하지 않았다 ... 여기 iOS : Tableview 다중 선택 - AccessoryCheckmark 재사용 가능한 셀 확인
내 코드입니다 :-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath
{
[employeeTable deselectRowAtIndexPath:[employeeTable indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [employeeTable cellForRowAtIndexPath:indexPath];
// get the letter in each section
NSString *alphabet = [charIndex objectAtIndex:indexPath.section];
// get the names beginning with the letter
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *names = [listOfNames filteredArrayUsingPredicate:predicate];
NSString *name = [names objectAtIndex:indexPath.row];
for(int i = 0; i < [employeeConnection.employees count]; i++)
{
Employee *aEmployee = [employeeConnection.employees objectAtIndex:i];
NSString *firstName = aEmployee.firstName;
NSString *lastName = aEmployee.lastName;
NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
if([fullName isEqualToString:name])
{
NSLog(@"Name: %@", name);
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
// Reflect selection in data model
[chosenEmployees addObject:aEmployee.employeeID];
[chosenEmployeesNames addObject:name];
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
// Reflect deselection in data model
[chosenEmployees removeObject:aEmployee.employeeID];
[chosenEmployeesNames removeObject:name];
}
}
}
}
업데이트 : 추가 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.textLabel.textColor = [UIColor whiteColor];
}
// Get the letter in the current section
NSString *alphabet = [charIndex objectAtIndex:[indexPath section]];
// Get the names beginning with the letter
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *names = [listOfNames filteredArrayUsingPredicate:predicate];
if([names count] > 0)
{
// Extract the name
cell.textLabel.text = [names objectAtIndex:indexPath.row];
}
return cell;
}
당신이 그들을 원하지 않을 때 검사되는 재사용 된 세포입니까? 주위를 스크롤 할 때와 마찬가지로? – larsacus
저는 약 14 개의 행을 섹션으로 나누었습니다 ... 예를 들어 첫 번째 행을 선택하면 다른 섹션의 다른 행이 선택됩니다 ... (섹션 - A : 1 (이 행을 확인합니다) 행, C : 1 2, P : 1, S : 1, T : 2) ... – user969043
당신은 할 것입니다. 'cellForRowAtIndexPath :'코드를 게시하거나 셀을 표시 할 셀을 설정하는 모든 방법. – larsacus