Here I have tried to get connected with the server. It says CONNECTION SUCCESSFUL. What I want to know is that that how can I go to another view when connection is successful?
I am a newbie please give your suggestion.. ?
here is the login button code
-(IBAction)loginButton:(id)sender
{
NSString *uName = [userName text];
NSString *pWord = [password text];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:uName forKey:@"uName"];
[defaults setObject:pWord forKey:@"pWord"];
[defaults synchronize];
NSLog(@"Data Saved");
NSString *post = [NSString stringWithFormat:@"&Username=%@&Password=%@", userName.text, password.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postlength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"myurl"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postlength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn){
if(conn){
MainView *mainView = [[MainView alloc]initWithNibName:@"MainScreen" bundle:nil];
self.mView = mainView;
}
NSLog(@"Connection successful");
}
else{
NSLog(@"Connection failed");
}
}
thanks in advance 🙂
You need to add the new view as a subview to show it. This will work if the class calling is the main view controller class: