私は iPhone プログラミングに非常に慣れていないので、非常に基本的な原則に関する知識がまったくないために問題が発生する可能性があります。
2 つのビューを持つ iPhone アプリを開発しています。最初のビューには 2 つのボタンがあり、ボタンの 1 つが押されると、テーブルビューを含むモーダルビュー ポップアップが表示されます。このテーブル ビューは、押されたボタンに応じて異なる方法で取り込まれます。ボタン button1 が押されると、テーブルビューに button1Data が入力されます。ユーザーはセルを選択できます。これが行われると、セルのアクセサリ タイプが UITableViewCellAccessoryCheckmark に設定されます。次に、チェックされたセルの名前を tableViewListChecked に保存します。これにより、データが変更されたときにどのセルをチェックする必要があるかを後で判断できます。
問題は次のとおりです。モーダルビューが閉じられ、button2 を選択した後、button1Data で選択されたセルが button2Data で選択されたままになります。データが変更されるため、関数 [theTableView reloadData] が機能していることは明らかですが、画面からセルをスクロールするまで、アクセサリーチューブは同じままです。
PS実際に画面のセルをスクロールすると、accessorytypeが正しく設定されます。
- (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];
cell.accessoryType = UITableViewCellAccessoryNone;
}
else if ([tableViewListChecked containsObject:[NSString stringWithString:cell.textLabel.text]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.textLabel.text = [tableViewList objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (![tableViewListChecked containsObject:[NSString stringWithString:cell.textLabel.text]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[tableViewListChecked addObject:[NSString stringWithString:cell.textLabel.text]];
}
else if ([tableViewListChecked containsObject:[NSString stringWithString:cell.textLabel.text]]) {
cell.accessoryType = UITableViewCellAccessoryNone;
[tableViewListChecked removeObject:[NSString stringWithString:cell.textLabel.text]];
}
}
助けてくれてありがとう!