In my app I create a bunch of UIButtons programmatically. Now when I add an action when the user taps the buttons, I do addTarget obviously. Now when I leave this view do I or should I call removeTarget on each UIButton, respectively?
Will there be any bugs or lingering side effects if I do not do this? If I then go back to this view and call addTarget on the UIButtons, will it overwrite the current target with the new one or will it create a bunch of targets for one button?
I just want to know so I don’t add a bunch of unnecessary lines of code to my app when there will not be issues.
You don’t need or should call removeTarget!
You should create your UIButtons in viewDidLoad and add the target there as well.
When you leave your view and the view gets destroyed the buttons should get destroyed anyway. When your view stays in the background and you go back to it your buttons are still there and they still have the target. No need to add a new one.