[Partial Solution] Getting an UISwitch in a table view cell to send an action message
[Partial Solution] Getting an UISwitch in a table view cell to send an action message
- Subject: [Partial Solution] Getting an UISwitch in a table view cell to send an action message
- From: WT <email@hidden>
- Date: Sun, 12 Apr 2009 14:30:04 +0200
Hello again,
it turns out that the standard behavior of rows with UISwitch
instances is NOT to treat equally a tap on the switch itself and a tap
on the part of the row rectangle that does not include the switch.
Apple's iPhone Settings application ignores taps on the row itself and
only responds to taps on the switch, in those cases.
So, a solution to my question is to replace
// This causes tapping the switch to send an action message to
// 'target'. Since the switch tag is set above, the target can
// extract the sender's section and row values from its tag.
cell.accessoryView = stateSwitch;
cell.accessoryAction = @selector(actionFlipRowState:);
cell.target = settings;
with
[stateSwitch addTarget: settings
action: @selector(actionFlipRowState:)
forControlEvents: UIControlEventValueChanged];
cell.accessoryView = stateSwitch;
and to return nil from -tableView:willSelectRowAtIndexPath: for the
rows with switches (which are all the rows, in my case). Then I don't
need to implement -tableView:didSelectRowAtIndexPath: at all, though
others would have to if their tables have rows without switches.
The replacement above works perfectly, but I still don't understand
why the code I presented before doesn't work. In that code snippet I
am using Apple's sanctioned way of having a switch in a cell fire an
action message, but the message isn't going out (as evidenced by the
fact that I don't get the log message printed out).
Incidentally, I also found out that sending a -setOn:animated: message
to a UISwitch instance does NOT trigger the switch to send its action
message (assuming it has one, and a target).
Anyway, as I said, I still don't understand why the code from my
previous message doesn't work so, if anyone knows, I'm still
interested in learning why.
Thanks.
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden