ダウンロードするファイルのリストを表示しているテーブルビューがあります。アクセサリボタンをタップすると、選択したファイルがダウンロードされます。詳細開示ボタンの画像を変更したい。出来ますか....?
そして、アクセサリビューで画像付きのボタンを使用した場合。このためのテーブルデリゲートメソッドはありますか...
ダウンロードするファイルのリストを表示しているテーブルビューがあります。アクセサリボタンをタップすると、選択したファイルがダウンロードされます。詳細開示ボタンの画像を変更したい。出来ますか....?
そして、アクセサリビューで画像付きのボタンを使用した場合。このためのテーブルデリゲートメソッドはありますか...
回答 2: その場合、独自のメソッドを作成して呼び出すことができます。
int row=indexPath.row;
UIButton *trackImageOnMap=[[UIButton alloc] initWithFrame:CGRectMake(420, 9, 40, 50)];
[trackImageOnMap setImage:[UIImage imageNamed:@"track_map_icon.png"] forState:UIControlStateNormal];
int iId=[[self.imageId objectAtIndex:row] intValue];
NSLog(@"iId=%d",iId);
[trackImageOnMap setTag:iId];
[trackImageOnMap addTarget:self action:@selector(trackImageOnMapButtonTouched:)forControlEvents:UIControlEventTouchDown];
[trackImageOnMap setContentMode:UIViewContentModeScaleToFill];
//[cell setAccessoryView:trackImageOnMap];
[cell addSubview:trackImageOnMap];
UIImageView を作成し、それを UITableViewCell の accessoriesView に割り当てることができます。
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessoryIcon"]] autorelease];
cell.accessoryView = imageView;
accessoriesView のボタンが必要な場合は、基本的に同じです。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"buttonImage"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventTouchUpInside];
button.tag = cell.indexPath;
cell.accessoryView = button;
デフォルトのタイプを置き換えたい場合は、UITableViewCell を上書きして次のコードを使用できます。
- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType
{
if (accessoryType == UITableViewCellAccessoryDisclosureIndicator)
{
self.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourNewImage.png"]] autorelease];
}
else
{
[super setAccessoryType:accessoryType];
}
}