How to change accessory type icon in UITableviewcell

I have a tabular view that displays a list of files to download. When I press the accessory button, it downloads the selected file. I want to change the image of the disclosure button. Is it possible??

And if I use the button with the image in the accessory. Is there a way to delegate a table for this ...

+3
source share
3 answers

Answer2: You can create your own method and call it in this case.

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];
+4
source

You can create a UIImageView and assign it to a UITableViewCell accessory.

UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessoryIcon"]] autorelease];
cell.accessoryView = imageView;

If you want a button for an accessory, this is basically the same:

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;
+3
source

If you want to replace the default type, you can overwrite UITableViewCell and use the following code:

- (void)setAccessoryType:(UITableViewCellAccessoryType)accessoryType
{
    if (accessoryType == UITableViewCellAccessoryDisclosureIndicator)
    {
        self.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourNewImage.png"]] autorelease];
    }
    else
    {
        [super setAccessoryType:accessoryType];
    }
}
0
source

All Articles