You probably aren't getting an image. Try using imageNamed: instead of the file one. I think that one needs a path.
OH MAN THAT DID SOMETHING!!!! Now there's an image (that I didn't create in Interface Builder) there. Only one, but I'm assuming that its just all 100 piled on top of each other. Maybe something is wrong with how I set the position? Woo! I feel so much closer!
Use NSLog again and see what the values are used when you set the frame of the generated imageviews.
Alright I did just that by doing
Code:
CGRect blockFrame = block[blockX][blockY].frame; //create a frame
blockFrame.origin = CGPointMake(island.center.x + (128 * blockX), island.center.y + (128 * blockY)); //assign the frame the desired coordinates of this UIImageView
block[blockX][blockY].frame = blockFrame; //assign the UIImageView the properties of the blockFrame I made
NSLog(@"block[%d][%d]'s frame is now set to %d", blockX, blockY, block[blockX][blockY].frame);
a chunk of the NSLog looks like this:
2010-12-30 22:45:27.636 Primal[12205:207] 2
2010-12-30 22:45:27.637 Primal[12205:207] block[9][6]'s frame is now set to 1151598592
2010-12-30 22:45:27.637 Primal[12205:207] Loop [9][6] finished
2010-12-30 22:45:27.637 Primal[12205:207] 0
2010-12-30 22:45:27.637 Primal[12205:207] block[9][7]'s frame is now set to 1151598592
2010-12-30 22:45:27.638 Primal[12205:207] Loop [9][7] finished
2010-12-30 22:45:27.638 Primal[12205:207] 1
2010-12-30 22:45:27.638 Primal[12205:207] block[9][8]'s frame is now set to 1151598592
2010-12-30 22:45:27.638 Primal[12205:207] Loop [9][8] finished
2010-12-30 22:45:27.639 Primal[12205:207] 1
2010-12-30 22:45:27.639 Primal[12205:207] block[9][9]'s frame is now set to 1151598592
2010-12-30 22:45:27.639 Primal[12205:207] Loop [9][9] finished
Well, your origin values are both based on .x. I assume one of those should be based on .y.
How much space do you have available? 128 is a sizable distance on an iPhone, maybe the others are off screen. Try 5 and see what happens.
Yeah the images are 128px x 128px but a couple fit on the screen at once. Yeah that was a typo I didn't notice, I changed it to .y and now where that special block was? its now lower, I'd assume by 128px. There has to be something wrong with my formula for calculating its position. Which is now set like this:
Code:
CGRect blockFrame = block[blockX][blockY].frame; //create a frame
blockFrame.origin = CGPointMake(island.center.x + (128 * blockX), island.center.y + (128 * blockY)); //assign the frame the desired coordinates of this UIImageView
block[blockX][blockY].frame = blockFrame; //assign the UIImageView the properties of the blockFrame I made
island is 128x128 UIImageView I placed in Interface Builder and is in the dead center of the view. I don't mind it being overlapped.
I'll know this code works correctly when I see squares surrounding island below and to the right, that weren't placed in Interface Builder.
NSLog(@"block[%d][%d]'s frame is now set to %@", blockX, blockY, NSStringFromCGRect(block[blockX][blockY].frame));
Here's a chunk of the NSLog with that:
2010-12-30 22:59:45.261 Primal[12421:207] 1
2010-12-30 22:59:45.261 Primal[12421:207] block[9][4]'s frame is now set to {{1312, 944}, {128, 128}}
2010-12-30 22:59:45.261 Primal[12421:207] Loop [9][4] finished
2010-12-30 22:59:45.261 Primal[12421:207] 2
2010-12-30 22:59:45.262 Primal[12421:207] block[9][5]'s frame is now set to {{1312, 1072}, {128, 128}}
2010-12-30 22:59:45.262 Primal[12421:207] Loop [9][5] finished
2010-12-30 22:59:45.262 Primal[12421:207] 1
2010-12-30 22:59:45.262 Primal[12421:207] block[9][6]'s frame is now set to {{1312, 1200}, {128, 128}}
2010-12-30 22:59:45.263 Primal[12421:207] Loop [9][6] finished
2010-12-30 22:59:45.263 Primal[12421:207] 2
2010-12-30 22:59:45.263 Primal[12421:207] block[9][7]'s frame is now set to {{1312, 1328}, {128, 128}}
2010-12-30 22:59:45.264 Primal[12421:207] Loop [9][7] finished
2010-12-30 22:59:45.264 Primal[12421:207] 1
2010-12-30 22:59:45.264 Primal[12421:207] block[9][8]'s frame is now set to {{1312, 1456}, {128, 128}}
2010-12-30 22:59:45.264 Primal[12421:207] Loop [9][8] finished
2010-12-30 22:59:45.265 Primal[12421:207] 0
2010-12-30 22:59:45.265 Primal[12421:207] block[9][9]'s frame is now set to {{1312, 1584}, {128, 128}}
2010-12-30 22:59:45.265 Primal[12421:207] Loop [9][9] finished
Now I see two images (I'm guessing the top-left corner of the 100UIImageViews) a little offset from the island. I'm assuming it's because the anchor point of all the programmatic UIImageViews is on their top-left. How do I set their anchor points to their center?
It's not the anchor point, it is the structure of a CGRect. It contains an origin and a size. The origin is at the top left.
UIViews (and thus, subclasses) have a center property. Instead of messing with the frame, you can just mess with the center.
Still... 1312 and higher... you're way off screen even on an iPad.
Don't worry that's kind of the point. I'm generating a map for the player to discover, the whole world isn't supposed to fit on the screen.
So I set the block[blockX][blockY].center = blockFrame.origin; like you said and voila! The code does exactly what I wanted it to do! Thank you SOOooo much for your help! Both of you, I learned a lot. You guys are awesome.