Quote:
Originally Posted by ng93
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //run when the user taps the screen
UITouch *touch = [touches anyObject]; //the users touch (or first touch if they are using > one finger)
CGPoint touchPosition = [touch locationInView:self.view]; //the position of the touch
CGFloat cellHeight = 20; //the width of the individual cells (all cells must be the same width and height for this to work)
CGFloat cellWidth = 20; //the height of the individual cells
int amountCellsWidth = 50; //how many cells you have in each row
int amountCellsHeight = 50; //how many cells you have in each column
for (int x=0; x<amountCellsWidth; x++) { //repeats the following code for the integer amountCellsWidth
for (int y=0; y<amountCellsHeight; y++) {//repeats the following code for the integer amountCellsHeight
if (touchPosition.y > y*cellHeight && touchPosition.y < (y+1)*cellHeight && touchPosition.x > x*cellWidth && touchPosition.x < (x+1)*cellWidth) { //works out if the touch was to the right of the cell's x position, to the left of the cells x position + the cells width, underneath the cells y position and above the cells y position + the cells height
[cell[x][y] setImage:yourImage]; //sets the tapped cells image to the UIImage yourImage
}
}
}
}
hope this helps
ng93
|
Sdk doesn't like this statement "[cell[x][y] setImage:yourImage];"
as 'cell' is undefined. Should cell be defined in the header as an 'int' or somewhere else.