각 섹션의 키가 포함 된 3 개의 NSArrays에서 가져온 3 개의 섹션으로 UITableView를 설정했습니다. 각 셀에 대한 detailTextLabels 및 액세서리보기를 수동으로 설정하기 위해 switch 문을 설정하려고했지만 표보기를 스크롤 할 때마다 셀이 겉으로보기에는 바뀌 었습니다. 이 작업을 수행하는보다 효율적인 방법이 있습니까?DetailTextLabel은 UITableViewCell에서 계속 변경됩니다.
이것은 내가 사용하려고 한 방법이다 :
switch (indexPath.section)
{
// info
case 0:{
cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
if ([cell.textLabel.text isEqualToString:@"Duration"])
{
cell.detailTextLabel.text = [task stringForDuration];
}
if ([cell.textLabel.text isEqualToString:@"Elapsed"])
{
// elapsed time
}
if ([cell.textLabel.text isEqualToString:@"Today"])
{
UISwitch *todaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[todaySwitch addTarget:self action:@selector(todaySwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
[todaySwitch setOn:task.isToday];
cell.accessoryView = todaySwitch;
[todaySwitch release];
}
}
break;
// actions
case 1:{
cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
if ([cell.textLabel.text isEqualToString:@"Priority"])
{
// priority
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
if ([cell.textLabel.text isEqualToString:@"Finish Early"])
{
// finish early
}
if ([cell.textLabel.text isEqualToString:@"Set New Time"])
{
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
if ([cell.textLabel.text isEqualToString:@"Repeating"])
{
UISwitch *repeatingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[repeatingSwitch addTarget:self action:@selector(repeatingSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
[repeatingSwitch setOn:task.isRepeating];
cell.accessoryView = repeatingSwitch;
[repeatingSwitch release];
//cell.detailTextLabel.text = nil;
}
}
break;
// details
case 2:{
cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
if ([cell.textLabel.text isEqualToString:@"Specifics"])
{
cell.detailTextLabel.text = task.specifics;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
if ([cell.textLabel.text isEqualToString:@"Repeated"])
{
// times repeated
}
}
break;
default:
break;
}
가 그리고 이것은 또 다른입니다 :
// Info section
if ([indexPath section] == 0)
{
// duration
cell.textLabel.text = [infoKeysArray objectAtIndex:indexPath.row];
if (indexPath.row == 0)
{
cell.detailTextLabel.text = [task stringForDuration];
}
// elapsed time
if (indexPath.row == 1)
{
//cell.detailTextLabel.text = [task stringForTotalElapsedTime];
}
// today status
if (indexPath.row == 2)
{
UISwitch *todaySwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[todaySwitch addTarget:self action:@selector(todaySwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
[todaySwitch setOn:task.isToday];
cell.accessoryView = todaySwitch;
[todaySwitch release];
}
}
// actions section
if ([indexPath section] == 1)
{
cell.textLabel.text = [actionsKeysArray objectAtIndex:indexPath.row];
// priority
if (indexPath.row == 0)
{
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
// finish early
if (indexPath.row == 1)
{
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
// set new time
if (indexPath.row == 2)
{
//cell.accessoryView = repeatingSwitch;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
// repeating
if (indexPath.row == 3)
{
UISwitch *repeatingSwitch = [[UISwitch alloc] initWithFrame:CGRectZero];
[repeatingSwitch addTarget:self action:@selector(repeatingSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
[repeatingSwitch setOn:task.isRepeating];
cell.accessoryView = repeatingSwitch;
[repeatingSwitch release];
cell.detailTextLabel.text = nil;
}
}
// details section
if ([indexPath section] == 2)
{
cell.textLabel.text = [detailsKeysArray objectAtIndex:indexPath.row];
// specifics
if (indexPath.row == 0)
{
//cell.detailTextLabel.text = taskDetails.specifics;
cell.detailTextLabel.text = task.specifics;
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
// repeated
if (indexPath.row == 1)
{
[cell setAccessoryView:nil];
}
}
이러한 시도는 모두 cellForRowAtIndexPath
정말 관련성이 높은 코드를 인용해야합니다. – Till
무슨 일이 일어나는지는 스크롤을 많이하면, 일부 셀의 액세서리보기와 다른 사람의 세부 텍스트 레이블이 모든 행에 표시되기 시작합니다. [indexPath section]은 전체 섹션을 나타내는 것이 아니라 표시된 섹션을 나타내는 것으로 보입니다. 적어도 그것이 저에게 의미있는 유일한 것입니다. – gurooj
세포가 재사용된다는 것을 알고 계시므로 이전에 유효한 설정이 계속 활성화되어 있습니까? 셀을 초기화 할 때 표시하거나 숨겨야하는 모든 것을 완전히 재설정해야합니다. – Till