tags:

views:

3138

answers:

4

I would like to use a custom version of the standard disclosure accessory image in my UITableView. How can I do this? I'm hoping that sub-classing UITableViewCell is not necessary for something this basic.

+6  A: 

You'll need to create a custom view and assign it to the accessoryView property of the UITableViewCell object. Something like:

myCell.accessoryView = [[ UIImageView alloc ] 
                       initWithImage:[UIImage imageNamed:@"Something" ]];
codelogic
Thanks, that worked great!
jpm
If I do this, I notice that the UITableViewDelegate method -[tableView:accessoryButtonTappedForRowWithIndexPath:] no longer gets called. Is that expected behavior? Is there a way to keep this method working?
Greg Maletic
There's some more explanation at http://stackoverflow.com/questions/869421/using-a-custom-image-for-a-uitableviewcells-accessoryview-and-having-it-respond
jarnoan
A: 

You don't need to subclass it. Just create a normal UITableViewCell, create your accessory view - any kind of UIView will do, which can of course contain subviews, and then set that as the accessoryView for your cell.

By default, a cell doesn't have an accessoryView - if you look at the property you'll see it's nil.

Airsource Ltd
A: 

I ran into the same problem as Greg--the accessory view doesn't track (if you use an UIImageView)

I solved it like this:

UIImage * image = [ UIImage imageNamed:@"disclosure-button-grey.png" ] ;
UIControl * c = [ [ UIControl alloc ] initWithFrame:(CGRect){ CGPointZero, image.size } ] ;

c.layer.contents = (id)image.CGImage ;
[ c addTarget:self action:@selector( accessoryTapped: ) forControlEvents:UIControlEventTouchUpInside ] ;
cell.accessoryView = c ;
[ c release ] ;
nielsbot
A: 
- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UIImage *indicatorImage = [UIImage imageNamed:@"Arrow.png"];
    cell.accessoryView =[[[UIImageView alloc]  initWithImage:indicatorImage] autorelease];


    return cell;
}

well i do this with the help code given above

STUPID PROGRAMMER