views:

21

answers:

2

i have got 24 buttons in my project.I need to manage them but I don't want to get my MainViewController polluted by 24 declarations of pointers, properties & synthesizes.

i was thinking about using buttonPushed functions and do it like:

> -(IBAction)buttonPushed:(id)sender{

> UIbutton *button=sender;

>[buttons addObjectAtIndex:[sender tag]];

>}

my question is:is sender a pointer to the IBObject?

edit:

I need to get a pointer to an object in interface builder which has not been clicked (so any (id)sender sent yet), what to do?

+1  A: 

Yes, the sender parameter will contain your button that was pushed. This design pattern was designed exactly for this, the case you have one method for multiple actions

Guy Ephraim
ok.what to do if I need to identify buttons before an action was called?example:i need to set image to a button which hasnt been clicked yet.
palominoz
well, this is a much tougher problem as you can't an object to a method only action, However one solution I can think of is on "viewDidLoad" go over all of the subviews of the view and "find" these buttons by scanning the list and identifying them somehow
Guy Ephraim
no way to access view objects by tag?lol
palominoz
+1  A: 

Yes, sender is the IBObject that sent the buttonPushed message. You can ask the sender (the button) for identifying information (such as the label) to decide what action to take.

Mr. Berna