It's important to say that I used another better solution than that.
On the iOS 6 we have a new thing called: CollectionViewController
It's a really better solution for this problem.
Question
I want to load my data from sqlite database
and position it on the view (one photo and the description).
How can I put the data in position X and Y after load it from the database?
I did a image to explain it (I'm developing for iphone 5
):
I think it maybe I can do it with CGRect
but I don't know exactly how.
Solution 2
It's important to say that I used another better solution than that.
On the iOS 6 we have a new thing called: CollectionViewController
It's a really better solution for this problem.
OTHER TIPS
Im not sure how to explain without giving a code as answer. but as a normal multidimension loop. Calculate the position and add the new image in the current subview (if able to do so).
The following not tested:
[EDIT: updated for correct indentation and syntax error]
CGFloat IMAGE_WIDTH = 150;
CGFloat IMAGE_HEIGHT = 150;
CGFloat LABEL_PADDING = 10;
for (int i = 0; i < [TOTAL_ROWS]; i++) {
// this is the initial frame for each row
CGRect newFrame = CGRectMake(0, i * IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT);
for (int j = 0; j < [TOTAL_COLUMNS]; j++) {
// but for column we need to more the x.position so its not stacking on itself
newFrame = CGRectMake(IMAGE_WIDTH * j,
newFrame.origin.y,
IMAGE_WIDTH,
IMAGE_HEIGHT);
UIImageView *newImageView = [[UIImageView alloc] initWithFrame:newFrame];
newImageView.image = [UIImage imageNamed:@"image.png"];
// create a label at the bottom of the image
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(newFrame.origin.x,
newFrame.origin.y +
newFrame.size.height +
LABEL_PADDING,
newFrame.size.width,
newFrame.size.height)];
[newLabel setText:[NSString stringWithFormat:@"description %d", j]];
NSLog(@"%@", NSStringFromCGRect(newFrame));
[self.view addSubview: newImageView];
[self.view addSubview: newLabel];
}
}