Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Zac atack303

macrumors newbie
Original poster
Apr 16, 2009
12
0
Well a little more complex than that I want to type in a text field then have it save to a txt file.

I also want to acces it. like readfromfile??? Or somthing???

Ps I tried [mytextfield writeToFile: @"mytext.txt" atomic: YES]; and it didn't work. (I assigned that line of code to a "done typing" button).
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
Well a little more complex than that I want to type in a text field then have it save to a txt file.

I also want to acces it. like readfromfile??? Or somthing???

Ps I tried [mytextfield writeToFile: @"mytext.txt" atomic: YES]; and it didn't work. (I assigned that line of code to a "done typing" button).

well ... why should that piece of code work? you just made up that method, it doesn't exist.

the easiest way to store data is NSUserDefaults ;-)
 

Zac atack303

macrumors newbie
Original poster
Apr 16, 2009
12
0
Seriously I got that method (writetofile) off of apple?!?

Could you give an example of the Ns data default thingy.
Also I need a table view to read that data. I'm makeing a sort of entrée list and to add an entrée I need the user to type a name and have it stored on the table view.

Btw I know that readfromfile doesn't exist, but writetofile I got at the apple iPhone developers page???
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
Seriously I got that method (writetofile) off of apple?!?

Could you give an example of the Ns data default thingy.
Also I need a table view to read that data. I'm makeing a sort of entrée list and to add an entrée I need the user to type a name and have it stored on the table view.

Btw I know that readfromfile doesn't exist, but writetofile I got at the apple iPhone developers page???

yes, but writeToFile is a method of NSData and you try to call it on UITextField which is no subclass of NSData.

read
http://developer.apple.com/iphone/l...ocoa/Conceptual/UserDefaults/UserDefaults.pdf
and
http://developer.apple.com/iphone/l...NSUserDefaults_Class/Reference/Reference.html
for an overview over NSUserDefaults. It's the basic class to store preferences in cocoa touch, it works very much like a NSDictionary (it is one, actually).

I never worked with table view's so far, but as far as I can see from the documentation you should use
cellForRowAtIndexPath:
to get the UITableViewCells. every cell has a text property which gives you the text. but table views are not THAT easy I suppose and it seems to me like you are pretty unexperienced, so you might should avoid them for now.
 

Zac atack303

macrumors newbie
Original poster
Apr 16, 2009
12
0
I am sort of unexperianced but not THAT unexerianced I read a book and I made a calculator (which is probably everyones first step) that handles decimals and powers (but not roots). Thanks for the help. Um how would one avoid useing tables when they need a list of entrees??? I appreciate the help.
 

Niiro13

macrumors 68000
Feb 12, 2008
1,719
0
Illinois
The three most common ways to save data is in a SQLite database, Property List (plist), or NSUserDefaults.

I find the SQLite example too buffed up so it's harder to follow so I never learned it...but it's definitely good to store large amounts of data.

Property Lists is what I use and I like it a lot. Property Lists use the writeToFile method.

Property Lists hold strings, numbers, dictionaries, booleans, arrays, data, and date.

You almost have it correct. The problem is that you said:
PHP:
[mytextfield writeToFile: @"mytext.txt" atomic: YES];

That's not a method for textfields. Also, you didn't specify a path. By default most people write to the Documents directory because that's the directory for read/write. What you can do is:

PHP:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
// The above code is to get the path to the documents directory.
[mytextfield.text writeToFile:[documentsDirectory stringByAppendingPathComponent:@"mytext.plist"] atomic: YES];
 

Zac atack303

macrumors newbie
Original poster
Apr 16, 2009
12
0
The three most common ways to save data is in a SQLite database, Property List (plist), or NSUserDefaults.

I find the SQLite example too buffed up so it's harder to follow so I never learned it...but it's definitely good to store large amounts of data.

Property Lists is what I use and I like it a lot. Property Lists use the writeToFile method.

Property Lists hold strings, numbers, dictionaries, booleans, arrays, data, and date.

You almost have it correct. The problem is that you said:
PHP:
[mytextfield writeToFile: @"mytext.txt" atomic: YES];

That's not a method for textfields. Also, you didn't specify a path. By default most people write to the Documents directory because that's the directory for read/write. What you can do is:

PHP:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
// The above code is to get the path to the documents directory.
[mytextfield.text writeToFile:[documentsDirectory stringByAppendingPathComponent:@"mytext.plist"] atomic: YES];

Hey thanks could you mabye give a more detailed examplr or a link to an iPhone developers page. If you could do that that'd be great thanks.
 

BlackWolf

macrumors regular
Apr 9, 2009
244
0
The three most common ways to save data is in a SQLite database, Property List (plist), or NSUserDefaults.

btw, NSUserDefaults is also just a .plist, it's the applications central settings file. if you have to store large amounts of data a seperate .plist or a sql database is probably your best choice, but for smaller stuff you can use NSUserDefaults.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.