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

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
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:mad:"greeting"];
[name resignFirstResponder];
greeting.text = @"Application Settings Saved!";

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

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

if(greetName == nil) {
greeting.text = @"guest registration";
} else {
name.text = [[NSString alloc] initWithFormat:mad:"%@",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:mad:"&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.
 

Jeremy1026

macrumors 68020
Nov 3, 2007
2,215
1,029
Post in the iPhone Development sub-forum, you'll get more responses there.
 

jjgraz

macrumors regular
Original poster
Feb 13, 2009
103
0
I posted in Iphone Programming.....didn't find the one labeled development. I'm sure you meant this one....thank you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.