Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in ARC project when adding a target after setting .on property #26

Open
markbeaton opened this issue Sep 10, 2012 · 6 comments
Open

Comments

@markbeaton
Copy link

If you add a target immediately after setting the "on" property, there's an EXC_BAD_ACCESS triggered when the switch slide animation completes.

E.g.

toggle.on = someBoolean;
[toggle addTarget:self action:@selector(aSelector:) forControlEvents:UIControlEventValueChanged];

Perhaps something to do with the [[self allTargets] makeObjectsPerformSelector:@selector(retain)]; and
[[self allTargets] makeObjectsPerformSelector:@selector(release)]; in the property setter - i.e. [self allTargets] is empty when the animation begins, but has the new target when the animation completes, causing an over-release?

@jyn
Copy link

jyn commented Sep 24, 2012

I can confirm this behaviour as well.

I solved it by setting the value AFTER the addTarget call. So

[toggle addTarget:self action:@selector(aSelector:) forControlEvents:UIControlEventValueChanged];
toggle.on = someBoolean;

@nickcheng
Copy link

@jyn 's solution worked. Thank you!

@thomasdao
Copy link

thanks so much for this :)

@pbodsk
Copy link

pbodsk commented Jan 21, 2013

@jyn 's solution worked for me as well. Thank you indeed 👍

@clementprem
Copy link

@jyn thank you so much ,, you saved mi day :)

@BrennaBlackwell
Copy link

@jyn is my hero!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants