I am trying to call a web service on page load. Currently I call it on a button click and it works fine. But when I try to do the same on viewDidAppear, it doesn’t happen. What i want to achieve is if username and password are saved then it should automatically load the next page. It is filling in the text boxes but not loading the next page.
Here is my code for submit button and ViewDidAppear:
-(IBAction)submitButton{
[apd showCoverView:YES WithActivityIndicator:YES];
PlaceWebService *handler = [[PlaceWebService alloc]init];
[handler setRequestType:Loginparser];
NSString *url = [NSString stringWithFormat:@"http://www.mywebsite.com/api.php?command=auth&cardno=%@&password=%@",username.text,password.text];
[handler sendingLoginRequest:url Respond:self At:@selector(showParsed:)];
}
and for viewDidAppear
-(void)viewDidAppear:(BOOL)animated
{
NSLog(@"Appeared");
[self loginArea];
apd=[[UIApplication sharedApplication]delegate];
NSString *filepath=[self pathOfFile];
if([[NSFileManager defaultManager]fileExistsAtPath:filepath])
{
NSArray *array=[[NSArray alloc]initWithContentsOfFile:filepath];
username.text=[array objectAtIndex:0];
password.text=[array objectAtIndex:1];
[self submitButton];
}
}
What should I do? Please help…
A couple things could be the problem here.
1)
IBActions usually take a parameter. Declare it as:
And then call it from your
viewDidAppearmethod as:2)
Also make sure UI stuff is happening on the main thread (you didn’t specify if the app is multi threaded or not), so maybe:
And
3)
Set breakpoints to see if your
submitButtonmethod (and the lines before it) are actually even called whenviewFromAppear:is called.And Rishi’s suggestion is good, too!