2

UITableViewCellStyleDefault スタイルを使用する UITableView があります。ディテール アクセサリも設定しました。

    cell.accessoryType= UITableViewCellAccessoryDetailDisclosureButton;

詳細アクセサリがプッシュされると、デリゲート メソッドaccessoryButtonTappedForRowWithIndexPath:が生成され、その特定のセルの画像が別の画像に変更されるようにコードが必要です。

どうやってやるの?どうにかしてセルを再作成する必要がありますか?

ありがとうございました!

4

5 に答える 5

3

いいえ、セルのイメージビューに他の画像を追加するだけです

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:@"IMAGENAME"];
于 2012-04-09T11:38:16.160 に答える
3
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *aCell = [tableView cellForRowAtIndexPath:indexPath];
    // Now You have your sekected cell, you can set the image which you have set on this cell
    UIImageView  *aView = (UIImageView*)[aCell viewWithTag:1];
    // Now change the image of aView
}
于 2012-04-09T11:41:56.737 に答える
2

あなたの accessoriesButtonTappedForRowWithIndexPath メソッドで --

UITableViewCell *cell = [tableView.delegate cellForRowAtIndexPath:indexPath];
cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]] autorelease];
于 2012-04-09T11:38:38.967 に答える
1

私はそれをやったことがありませんが、IDは次のようなことを試してください

-accessoryButtonTappedForRowWithIndexPath..{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // change the view of cell here
}

単なるアイデアです。これまでに試したことのコードを質問に追加してください。

于 2012-04-09T11:34:45.467 に答える
1

基礎となるデータ構造のイメージを変更します。その後、適切なインデックス パスでセルをリロードします。

たとえば、データが NSDictionary オブジェクトを含む単純な NSArray であると仮定します。ディクショナリには、「テキスト」や「イメージ」などのいくつかのキーが含まれています。cellForRowAtIndexPath:適切なディクショナリの値を使用して、cell.text と cell.image を設定します。

だから、accessoryButtonTappedForRowWithIndexPath:(または多分あなたがしたいdidSelectRowAtIndexPath:ですか?)、あなたはそのようなことをします:

NSDictionary* dict = [myArray objectAtIndex:indexPath.row];
[dict setValueForKey:@"image":myNewImage];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];

これは疑似コードであり、テストされていませんが、それを行う方法がわかります。

于 2012-04-09T11:37:45.383 に答える