views:

64

answers:

2

Hello, I want to program an application on iPhone and I want to know if the idea of this application is doable. So in the Application I want to have an image that appears to the users (this is easy. When the user touches the image, the application records the (x,y) position of where the user touches exactly in the image and stores it in a file (.pdf, .txt or what ever) I need these (x,y) positions to be stored in some kind of file but I don't know if this is doable in iPone or iPad

Thank you

+1  A: 

sure. Each app gets its own place to save things to. You would write out a file just like any other program. Some locations are meant to be temporary, some are meant to be backed up when synced with iTunes.

You could also use Core Data to persist these x,y locations.

darren
+2  A: 

Yes this is perfectly doable. You would have to:

Create a custom view. Override the touchesBegan:withEvent: method with code like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint locationOfTouch = [touch locationInView:self];
    // You can now use locationOfTouch.x and locationOfTouch.y as the user's coordinates
}

Save the CGPoint. You can create a NSDictionary of it like this:

NSDictionary *coordinates = (NSDictionary *) CGPointCreateDictionaryRepresentation(locationOfTouch);

Then write it to a file:

[coordinates writeToFile:filePath atomically:YES];

That's all.

Rits
Thanks a lot. Where can I find this file that saves the coordinates and in which format it will be saved
Miss.n
I don't think UITouch objects are able to be archived, which means the writeToFile will fail...
Kendall Helmstetter Gelner
Thank you for you help
Miss.n
Where should I write : [coordinates writeToFile:filePath atomically:YES];is it supposed to be written in the .h?
Miss.n
@Kendall: That's why I am creating a NSDictionary representation of it. The `writeToFile` is archiving a NSDictionary, not a UITouch object.
Rits
@Miss.n: You can put it all in the `touchesBegan:withEvent:` method. You have to specify the location for yourself. I'd recommend the application's Documents folder.
Rits
doesn't writeToFile overwrite the existing file? He wants to save all of the points which would be more like an append.
darren
Yes, I have an array of images and for each image I need to save all the points.
Miss.n
@Miss: I see, I wasn't sure the dictionary representation was archivable but I guess it must be underneath...
Kendall Helmstetter Gelner