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.
views:
3138answers:
4
+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
2008-12-31 19:01:33
Thanks, that worked great!
jpm
2008-12-31 19:05:49
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
2010-01-05 01:54:47
There's some more explanation at http://stackoverflow.com/questions/869421/using-a-custom-image-for-a-uitableviewcells-accessoryview-and-having-it-respond
jarnoan
2010-10-06 13:21:45
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
2008-12-31 19:02:15
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
2010-01-08 08:08:30
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
2010-08-20 04:55:54