Reputation: 363
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...
Upvotes: 0
Views: 323
Reputation: 89509
A couple things could be the problem here.
IBActions usually take a parameter. Declare it as:
- (IBAction) submitButton: (id) sender;
And then call it from your viewDidAppear
method as:
[self submitButton: self];
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:
[self performSelectorOnMainThread: @selector(submitButton:) withObject: self];
And
Set breakpoints to see if your submitButton
method (and the lines before it) are actually even called when viewFromAppear:
is called.
And Rishi's suggestion is good, too!
Upvotes: 0
Reputation: 11839
If you want to call the method after loading view and without any event, then you need to that as normal instance method instead of IBAction method. -(Void)submitButton{ // implementation }
and then call this method from viewDidAppear.
Upvotes: 2