私のiPhoneアプリケーションには、24時間すべてのリストを含むグループ化されたテーブルビューがあります。ユーザーがテーブルビューでセルの1つを選択すると、アクセサリビューにチェックマークが表示され、NSUserDefaultsを介してデータが保存されます。ユーザーが前方にビューをロードすると、これはNSUserDefaultsから情報を引き出し、対応するセルにチェックマークを表示する必要があることを意味します。このビューでスクロールを開始するまで、これは正常に動作します。そして、この問題が発生した:UITableViewは上下にスクロールしてセルを選択しています
私が設定している私のdidSelectRowAtIndexPath
まで1行が選択された場合に、他のすべての選択が解除されるように。これはうまく動作しますが、リストをスクロールするだけで、一見無作為な項目が選択され始めます。数回スクロールしていくと、すべてのアイテムが選択されます。セルの1つをクリックすると、その1つのセルが選択され、他のセルは選択解除されます(これが選択されている必要があります)。
しかし、どのようにセルがスクロールするだけで選択されますか?ここでの問題はおそらく配置されている私の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