24 시간 내 모든 목록을 포함하는 내 iPhone 응용 프로그램에 그룹화 된 표보기가 있습니다. 사용자가 테이블 뷰에서 셀 중 하나를 선택하면 액세서리 뷰에 체크 표시가 나타나고 NSUserDefaults를 통해 데이터를 저장합니다. 사용자가 앞으로보기를로드 할 때 이것은 NSUserDefaults에서 정보를 가져 와서 해당 셀에 체크 표시를해야한다는 것을 의미합니다. 보기에서 스크롤을 시작할 때까지이 작동합니다. 그리고 이런 일이 발생 :UITableView가 위아래로 스크롤하여 셀을 선택합니다.
내가 설정 한 내 didSelectRowAtIndexPath
한 행을 선택하면, 다른 사람들은 모두 해제되도록. 이것은 정상적으로 작동하지만, 목록을 스크롤하는 것만으로, 무작위로 보이는 항목이 선택되기 시작합니다. 몇 번 위아래로 스크롤하면 모든 항목이 선택됩니다. 셀 중 하나를 클릭하면 해당 셀이 선택되고 다른 셀은 선택 취소됩니다 (이것이 있어야합니다).
그러나 어떻게 셀이 단지 스크롤링에 의해 선택 될까요? 여기에 문제가 아마도 위치 내 cellForRowAtIndexPath
방법입니다 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue;
if (indexPath.row == 0) {
cellValue = @"00:00";
} else if (indexPath.row == 1) {
cellValue = @"01:00";
} else if (indexPath.row == 2) {
cellValue = @"02:00";
} else if (indexPath.row == 3) {
cellValue = @"03:00";
} else if (indexPath.row == 4) {
cellValue = @"04:00";
} else if (indexPath.row == 5) {
cellValue = @"05:00";
} else if (indexPath.row == 6) {
cellValue = @"06:00";
} else if (indexPath.row == 7) {
cellValue = @"07:00";
} else if (indexPath.row == 8) {
cellValue = @"08:00";
} else if (indexPath.row == 9) {
cellValue = @"09:00";
} else if (indexPath.row == 10) {
cellValue = @"10:00";
} else if (indexPath.row == 11) {
cellValue = @"11:00";
} else if (indexPath.row == 12) {
cellValue = @"12:00";
} else if (indexPath.row == 13) {
cellValue = @"13:00";
} else if (indexPath.row == 14) {
cellValue = @"14:00";
} else if (indexPath.row == 15) {
cellValue = @"15:00";
} else if (indexPath.row == 16) {
cellValue = @"16:00";
} else if (indexPath.row == 17) {
cellValue = @"17:00";
} else if (indexPath.row == 18) {
cellValue = @"18:00";
} else if (indexPath.row == 19) {
cellValue = @"19:00";
} else if (indexPath.row == 20) {
cellValue = @"20:00";
} else if (indexPath.row == 21) {
cellValue = @"21:00";
} else if (indexPath.row == 22) {
cellValue = @"22:00";
} else if (indexPath.row == 23) {
cellValue = @"23:00";
}
if ([[prefs valueForKey:@"quiet_hours_time_interval_from"] isEqualToString:cellValue]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.textLabel.textColor = [UIColor colorWithRed:72.0/255 green:104.0/255 blue:152.0/255 alpha:1];
}
cell.textLabel.text = cellValue;
return cell;
}
prefs
이 [NSUserDefaults standardUserDefaults]
동일이와 나는 quiet_hours_time_interval_from
키에 (제대로) 선택된 셀의 정확한 값을 저장합니다.
여러분이 도와 드리 길 바랍니다.
그래서 작동합니다. 간단한 솔루션. 고마워. – wstr