Transferring object data using UIButton press

I created a custom UIView FormDropdown class containing a question and a button in nib. The class also has an NSArray property, which should store various options for the button.

Thus, you can make this button, for example, using the viewDidLoad method:

FormDropdown *dropdown = [FormDropdown dropdownWithQuestion:@"This is an example question" andLabel:@"Select one" andOptions:[NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]]; [self.view addSubview:dropdown]; 

Obviously, I would like the button, when pressed, to display the UIPickerView with the displayed options. But I was fixated on how to send parameters to any method. I know that I can attach an action to a button like this:

 [dropdown.dropdownButton addTarget:self action:@selector(dropdownPressed:) forControlEvents:UIControlEventTouchUpInside]; 

.. but I don’t see how to pass parameters from the dropdown.options array to a method?

+6
ios objective-c iphone uibutton uiview
source share
2 answers

I believe that you can do this by adding an “associative link” from UIButton to the object data.

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocAssociativeReferences.html

+1
source share

I am also looking for a way to do this ... however, this is not possible.

My possible solution. I think I'm going to subclass UIButton and add the property "NSObject * tagObject" to it.

It seems to be something wrong? (I use ARC, and I wonder if this will cause the objects to remain in memory - I don’t think so).

0
source share

All Articles