Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 7, 2009, 04:14 PM   #1
jjgraz
macrumors regular
 
Join Date: Feb 2009
View to View NSUserDefault - Source code included

I apologize if this post is long. I have two issues i'm trying to work out.

Short:
1) accessing the user defaults from one view which live on a separate view.
2) having the user settings view open upon first launch, then once updated and saved with NSUserDefaults....open the normal first view next time app is opened. (note: not using a settings bundle)

Below is my code. I have created a preferences view which acts as a settings view. It works fine. I have another main page view which has my app and a button on it that sends data to a web service, It works fine as well.

Now, I want to send both at once to the web service with the button on the main page view. Any ideas on how this is done? Please see the code below.

code for preferences viewController.m

-(IBAction) updatePrefs:(id)sender {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:name.text forKey:@"greeting"];
[name resignFirstResponder];
greeting.text = @"Application Settings Saved!";

}
- (void)viewDidLoad {
[super viewDidLoad];

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *greetName = [prefs stringForKey:@"greeting"];

if(greetName == nil) {
greeting.text = @"guest registration";
} else {
name.text = [[NSString alloc] initWithFormat:@"%@",greetName];
}


This Works........How do I pull up what was inputted and saved here....In my other View, and include it in the button action to send to web service.

Here is sample code from second ViewController.m which sends to webservice.

- (IBAction)buttonPressed:(id)sender
{
NSString *myRequestString = [[NSString alloc] initWithFormat:@"&lastname=%@", lastName.text];
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [ NSURL URLWithString: @"http://websitename.com/phpwebservicename/name.php" ] ];
[ request setHTTPMethod: @"POST" ];
[ request setHTTPBody: myRequestData ];

NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];}




secondly, How does one make tell the app if viewpreferences are at default....then open that page first, if not, open a different view.

Any expertise on these two subjects will be greatly appreciated.....Thanks a million.
jjgraz is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
View page source MBPDiva OS X 10.8 Mountain Lion 2 Apr 3, 2013 10:33 PM
[HELP] Create view from code for DetailView. SmartiOS iPhone/iPad Programming 5 Jan 30, 2013 07:55 AM
Find location of table view cell that calls view controller moonman239 iPhone/iPad Programming 3 Nov 24, 2012 05:31 PM
Pushing to a Detail View from a Table View Cell using Xcode Storyboard xcodeApp10 iPhone/iPad Programming 2 Sep 17, 2012 03:45 PM
Passing Data between View Controllers : from uitableview to a details view controller EliasRahme iPhone/iPad Programming 7 Jul 20, 2012 08:04 AM

Forum Jump

All times are GMT -5. The time now is 05:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC