I want to have a couple of controls on the right side of my cell. Specifically, I need a UILabel and a UIButton. When the button is touched, I want to update the label.
If I remove the label and assign the button as the accessoryView (cell.accessoryView = button), it works properly and I get my events.
If I create a UIView, assign that as the accessoryView, and add the label and button as subViews of the accessoryView, I don't get any events for the button.
UIFont *font = [UIFont systemFontOfSize:12];
UILabel *label = [[[UILabel alloc] init] autorelease];
label.text = @"some text";
label.frame = CGRectMake(210, 10, 70, 25);
label.textAlignment = UITextAlignmentRight;
label.font = font;
[cell.accessoryView addSubview:label];
// Add the button
UIButton* accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
[accessoryButton addTarget:self action
selector( touchedRow: ) forControlEvents:UIControlEventTouchUpInside];
[accessoryButton setFrame:CGRectMake(281, 10, 30, 25)];
[accessoryButton setImage:[UIImage imageNamed
"TrackingDot.png"] forState:UIControlStateNormal];
[accessoryButton setUserInteractionEnabled:YES];
[cell.accessoryView addSubview:accessoryButton];
I tried enabling user interaction on both the table row and the accessoryView itself, to no avail. I also tried assigning the event handler to the accessoryView, rather than the button, itself. But, of course, UIView doesn't respond to that message.
I am begging for any suggestions. I have been banging my head on this wall for a couple of days and can't seem to get past it.
If I remove the label and assign the button as the accessoryView (cell.accessoryView = button), it works properly and I get my events.
If I create a UIView, assign that as the accessoryView, and add the label and button as subViews of the accessoryView, I don't get any events for the button.
UIFont *font = [UIFont systemFontOfSize:12];
UILabel *label = [[[UILabel alloc] init] autorelease];
label.text = @"some text";
label.frame = CGRectMake(210, 10, 70, 25);
label.textAlignment = UITextAlignmentRight;
label.font = font;
[cell.accessoryView addSubview:label];
// Add the button
UIButton* accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
[accessoryButton addTarget:self action
[accessoryButton setFrame:CGRectMake(281, 10, 30, 25)];
[accessoryButton setImage:[UIImage imageNamed
[accessoryButton setUserInteractionEnabled:YES];
[cell.accessoryView addSubview:accessoryButton];
I tried enabling user interaction on both the table row and the accessoryView itself, to no avail. I also tried assigning the event handler to the accessoryView, rather than the button, itself. But, of course, UIView doesn't respond to that message.
I am begging for any suggestions. I have been banging my head on this wall for a couple of days and can't seem to get past it.