tags:

views:

719

answers:

2

Hello,

I've created a subclass of UIButton to allow me to have a checkbox on the iPhone. This checkbox is part of a subclass of UITableViewCell.My question is how I can attach an action to the button being pressed and have that method implemented in the tableView controller?

I tried using the addTarget:action: method but this doesn't seem to work. One option is to use the App Delegate but this isn't good programming practice.

All advice is welcome.

Bart

A: 

Make sure the button receives the touch event. You could check this by overriding

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event

or

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

Log something or set a breakpoint on either of those. If your button is not receiving touches (which I think it doesn't) try setting exclusiveTouch on the TableView and/or the TableViewCell to NO.

klaaspieter
It does take touches though. It's a bit odd.
+1  A: 

First, when you say the checkbox is part of a subclass of UITableViewCell, what do you mean? How are you adding it?

Second, what do you mean by addTarget:action: "doesn't seem to work." I assume you mean addTarget:action:forControlEvents: here. Which controlEvents are you passing? A small amount of code, and some details about "doesn't work" would be helpful here.

Rob Napier