I tried creating UIButtons from an Array of objects. I created these successfully by using
float x=0,y=0;
for( NSMutableDictionary *dict in places)
{
NSLog(@"x: %f",x);
x=x+25;
y=y+25;// Vary these depending on where you want the buttons to be
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(x,y,25,25)] autorelease];
button.backgroundColor=[UIColor redColor];
[self addSubview:button];
}
but I need some way to make all of these buttons accesible by other methods in my class, particularly a method that is triggered by the CLLocation delegate (or some other ways, even by user interaction) and which animates any of the buttons.
Hope anyone can help me!
btw: the object “places” is an Array of MutableDictionaries.
Thank you!
Create a mutable collection for keeping the references to the buttons. If you need to have them ordered somehow, create NSMutableArray, if not, create NSMutableSet. In the header file declare the ivar like NSMutableSet buttonsSet, then in the class implementation:
Note that the buttons are accessible also through self.subviews array.