Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

Thread: Creating A Grid
View Single Post
Old 03-19-2010, 11:11 AM   #14 (permalink)
evmacdev
Registered Member
 
Join Date: Jan 2010
Posts: 6
evmacdev is on a distinguished road
Default

Quote:
Originally Posted by ng93 View Post
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.
evmacdev is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,545
Threads: 94,071
Posts: 402,693
Top Poster: BrianSlick (7,989)
Welcome to our newest member, ceolacc18
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.