Im very new on this, I have been locking for 2 days if it is possible to do this:
in my .h file I have:
@interface puzzle2ViewController : UIViewController {
IBOutlet UIImageView *pza1;
IBOutlet UIImageView *pza2;
.....
}
@property(assign) IBOutlet UIImageView *pza1;
@property(assign) IBOutlet UIImageView *pza2;
in my .m file I have:
#define kNumeroDePiezas 2
piezas = [[NSMutableArray alloc] initWithCapacity:kNumeroDePiezas];
for(int i = 0; i < kNumeroDePiezas; i++) {
UIImageView *myView = [NSString stringWithFormat:@"pza%d", i];
[piezas addObject:myView];
}
As you can see I want to add the UIImageView dynamically to a NSMutableArray. Why? because I whant it dynamic, now I have 2 images but probably I will have 10 or 20 images.
The images are in the interface builder with reference outlets already seted up.
Im very new on this, I have been locking for 2 days if it is possible to do this:
in my .h file I have:
@interface puzzle2ViewController : UIViewController {
IBOutlet UIImageView *pza1;
IBOutlet UIImageView *pza2;
.....
}
@property(assign) IBOutlet UIImageView *pza1;
@property(assign) IBOutlet UIImageView *pza2;
in my .m file I have:
#define kNumeroDePiezas 2
piezas = [[NSMutableArray alloc] initWithCapacity:kNumeroDePiezas];
for(int i = 0; i < kNumeroDePiezas; i++) {
UIImageView *myView = [NSString stringWithFormat:@"pza%d", i];
[piezas addObject:myView];
}
As you can see I want to add the UIImageView dynamically to a NSMutableArray. Why? because I whant it dynamic, now I have 2 images but probably I will have 10 or 20 images.
The images are in the interface builder with reference outlets already seted up.
Hope somebody can help me, thanks.
Yes, you can certainly store image views into an array. An NSArray will hold ANY object.
However, your code is creating strings, and saving those to an array.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
2011-04-09 15:16:54.810 puzzle2[14422:207] the array is 0.000000
2011-04-09 15:16:54.812 puzzle2[14422:207] the array is 0.000000
Thanks
I don't understand what you're trying to do. Are you saying that you have a bunch of image views that you defined in Interface builder and you want to put THOSE into an array?
In that case, I would suggest using tags. There is a UIView method viewWithTag that finds a subview with a particular numeric tag. You could set up your image views in IB with tags that start at 1 and go up from there, and then use code like this:
Note that you should use the "%@" format string to display an array (or any other object.) The "%f" format string you used in your log statement is for displaying a floating point value, and you will get odd results if you try to log an object with that format.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Thats exactly what I was looking for!!!! I read something about tags but I did not put atention, that is why I will never found a solution. thanks so much for your help so I can continue with my little project.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.