b.dot
b.dot

Reputation: 109

DCRoundSwitch In Custom Cell Fires On Table Reload

I have a UITableView containing four rows. Each row has a custom cell with a DCRoundSwitch. The value-changed event is linked in IB to a switchChanged method. Each time a new cell with a switch is needed in cellForRowAtIndexPath I assign the new cell's switch to an ivar so I can control it programmatically like this:

       self.categorySwitch = ((FilterViewCell *)cell).sectionSwitch; 

After I touch a switch the first time it works perfectly, triggering the switchChanged method.

The problem: Every time a new cell is needed or the table is reloaded, it fires off the switchedChanged method without touching the switch. I've tried the removing all targets at the end of the switchChanged method like so but it still didn't work:

       [theSwitch removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];

This works perfectly using UISwitch.

Any suggestions? DCRoundSwitch appears to be an excellent alternative and I would like to use it.

Thanks

Upvotes: 1

Views: 296

Answers (2)

Raymond Ni
Raymond Ni

Reputation: 11

In DCRoundSwitch.m file, locate method:

- (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)ignoreControlEvents

Delete these two lines:

[[self allTargets] makeObjectsPerformSelector:@selector(retain)];
[[self allTargets] makeObjectsPerformSelector:@selector(release)];

Upvotes: 1

niks
niks

Reputation: 554

Try to change event to UIControlEventTouchUpInside as given below...

   [theSwitch removeTarget:nil action:NULL forControlEvents:UIControlEventTouchUpInside];

Also change event in setOn:animated: method in DCRoundSwitch.m file

   [self sendActionsForControlEvents:UIControlEventTouchUpInside];

Upvotes: 0

Related Questions