さて、私はゆっくりとこれを理解しています。もう1つだけ問題があります。私は文字列を使用しており、文字列がセルテキストと等しい場合は、tableView をロードするときにチェックマークを付けると言っています。
そのための私のコードは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ([cell.textLabel.text isEqualToString:transferData]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
次に、そのチェックマークを削除し、選択されたときにそれに応じてチェックマークを追加するように指示しています:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
cell.accessoryType = UITableViewCellAccessoryNone;
UITableViewCell *cellCheck = [tableView
cellForRowAtIndexPath:indexPath];
cellCheck.accessoryType = UITableViewCellAccessoryCheckmark;
transferData = cellCheck.textLabel.text;
NSLog(@"%@", transferData);
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* uncheckCell = [tableView
cellForRowAtIndexPath:indexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
最初のロード時を除いて、すべて正常に動作します。何らかの理由で、別のセルを選択すると、最初に tableView に読み込まれたチェックマークが消えません。どうしてこれなの?