in my application i'm using a UIButton
(myButton) wich i added via Storyboard
.
So, when tapping the button an IBAction
gets called:
-(IBAction)buttonAction:(UIButton*)sender{
[myCustomClass doSomeCrazyStuff];
[sender setEnabled:NO];
}
As you can see, i'm calling a method from myCustomClass
( myCustomClass
is a REST-Client for my web-service).
The viewController
the button lays in is delegate of myCustomClass
.
There are two delegate methods implemented, one for success and one for error.
-(void)requestSucceeded{
/* If the request succeeded i want the button to be enabled again, and it's selected
state inverted */
NSLog(@"This gets called");
[myButton setEnabled:YES];
[myButton setSelected:!myButton.selected];
}
This works totally fine: i press the button, stuff is done on myCustomClass
, request succeeds, button is set to inverted selected state.
But now for the other delegate method:
-(void)requestFailed{
/* If the request failed i want the button to be enabled again, and it's selected
state stays the same */
NSLog(@"That gets called");
[myButton setEnabled:YES];
}
If requestFailed
gets called, the console prints That gets called as expected, but the button stays disabled... and i don't know why.
I tried other things in requestFailed
like:
[myButton setHidden:YES];
Just to see if the reference to myButton
is working...
And it is.
Probably i'm missing something right now, but i can't figure it out.
Thanks for your help.
EDIT:
I don't think requestFailed
could be called from a different thread (as @gonji-dev mentioned), since both requestSucceeded
and requestFailed
are called from the same method.
In my doSomeCrazyStuff
method i set up a completion block wich handles connection success and error. If an error occurred it gets handled in another class. If the connection succeeded i'm asking for HTTP status codes to decide wether requestFailed
or requestSucceeded
will be called.