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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-25-2010, 10:06 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default How to save text in Uitextview

Notes as a UITextView in navigation base application .How to save text data after writing in notes
rk_mail04 is offline   Reply With Quote
Old 12-25-2010, 10:06 AM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Save to where? If you want to save to the device you can use NSUserDefaults.
baja_yu is offline   Reply With Quote
Old 12-25-2010, 12:01 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

Yes , i need to save device . Whenever user want to write text i need to see previous page if want, and continuous from previous page to to starting of current to write .

Quote:
Originally Posted by baja_yu View Post
Save to where? If you want to save to the device you can use NSUserDefaults.
rk_mail04 is offline   Reply With Quote
Old 12-25-2010, 12:08 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

In that case as I said, NSUserDefaults should work just fine.
baja_yu is offline   Reply With Quote
Old 12-25-2010, 12:42 PM   #5 (permalink)
German iPhone dev
 
Join Date: Jun 2009
Location: Düsseldorf
Age: 19
Posts: 28
Gi-lo is on a distinguished road
Send a message via AIM to Gi-lo
Default

How to save text depends on your situation. NSUserDefaults is designed to hold small data like settings. If you need to save a whole text then you should use "writeToFile:" to store it in the TMP or an own cache folder.
__________________
Please follow me on Twitter and take a look at my website.
Feel free to add me on AIM (GiloMTTM) to ask me whatever you want
Gi-lo is offline   Reply With Quote
Old 12-25-2010, 02:44 PM   #6 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

plz post some sample

Quote:
Originally Posted by Gi-lo View Post
How to save text depends on your situation. NSUserDefaults is designed to hold small data like settings. If you need to save a whole text then you should use "writeToFile:" to store it in the TMP or an own cache folder.
rk_mail04 is offline   Reply With Quote
Old 12-25-2010, 02:54 PM   #7 (permalink)
German iPhone dev
 
Join Date: Jun 2009
Location: Düsseldorf
Age: 19
Posts: 28
Gi-lo is on a distinguished road
Send a message via AIM to Gi-lo
Default

Code:
        // Save
	NSString *someText = @"Bla bla bla bla :P";
	[[NSUserDefaults standardUserDefaults] setObject:someText forKey:@"MyTextIsHere"];
	 
	// Load
	NSString *mySavedString = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyTextIsHere"];
	NSLog(@"%@", mySavedString);
Super easy
__________________
Please follow me on Twitter and take a look at my website.
Feel free to add me on AIM (GiloMTTM) to ask me whatever you want
Gi-lo is offline   Reply With Quote
Old 12-25-2010, 02:56 PM   #8 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Quote:
Originally Posted by rk_mail04 View Post
plz post some sample
Try the Search functionality on the forum. If you've searched for NSUserDefaults you would have gotten plenty of examples.
baja_yu is offline   Reply With Quote
Old 12-25-2010, 04:15 PM   #9 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 327
thomashw is on a distinguished road
Default

I wouldn't use NSUserDefaults for saving large amounts of text. Like Gi-lo mentioned, writing to a file would work.
thomashw is offline   Reply With Quote
Old 12-25-2010, 04:44 PM   #10 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Never tried to write a large string so I don't know what the downside is, if any. NSString has methods for reading from and saving to a file so that solution is trivial too.
baja_yu is offline   Reply With Quote
Old 01-07-2011, 05:38 AM   #11 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 90
rk_mail04 is on a distinguished road
Default

added done save button in naviagtion bar right . .Text i can able to see in console uisng nslog in saveAction method , but i am not getting my current folder for savedText.text file. how to check my file. Same time i need to restore my text data in my notes , please guide me

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Notes";

// the nav bar's custom Done button right view
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(saveAction] autorelease];

self.navigationItem.rightBarButtonItem = addButton;


}

- (void)saveActionid)sender
{
// finish typing text/dismiss the keyboard by removing it as the first responder
//
[self.textview resignFirstResponder];
//self.navigationItem.rightBarButtonItem = nil; // this will remove the "save" button

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:@"savedText.txt"];
NSString *savedString = textview.text;

NSLog(@"The Save file is:%@", savedString);

[savedString writeToFile:documentTXTPath atomically:YES];
}

Quote:
Originally Posted by baja_yu View Post
Never tried to write a large string so I don't know what the downside is, if any. NSString has methods for reading from and saving to a file so that solution is trivial too.
rk_mail04 is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, uitextview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 388
8 members and 380 guests
chemistry, daudrizek, jeroenkeij, Kirkout, PavelMik, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:01 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0