views:

157

answers:

1

I have an increase button and a decrease button, both of which affect a variable. The variable has a minimum and the decrease button will be disabled once that minimum is reached. Likewise for the maximum value of the variable. In my controller, I have two IBActions for both the increase and decrease actions, and two IBOutlets, in order to disable the buttons accordingly. At the bottom of my KVO statement to handle the value change, I have:

increaseButton.enabled = value != MAX;
decreaseButton.enabled = value != MIN;

While this code is functional, I can't help but feel that feel this is a naive approach to the problem, especially since this requires 4 connections. Is there a better solution to this, one that uses fewer connections?

A: 

This is a perfectly good approach, in my opinion. If there was a possibility that you might add more buttons, with other rules, or that you would need more flexibility in some other way, then it might be worth thinking about making the code smarter somehow. But here you know what you want, and you've implemented it and it works. So what's there not to like?

If you wanted to decrease the number of connections (but I don't think this is a value in and of itself), you could add the target yourself using the IBOutlets, instead of using the IBActions. But again, I don't think there is any point in doing that.

Felixyz