Reputation: 4551
i am using ASIHttpRequest in my iOS project. In the requestFail i am doing like this :
#pragma mark Erreur requête de connexion
- (void)requestFailed:(ASIHTTPRequest *)request
if([[request error] code] == ASIConnectionFailureErrorType )
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Erreur de connexion"
message:@"Connexion avec le serveur impossible : vérifiez vos paramètres réseaux."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else if ([[request error] code] == ASIRequestTimedOutErrorType)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Erreur de connexion"
message:@"La requête a expiré !"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Erreur de connexion"
message:@"Une erreur inconnue est survenue."
delegate:nil
cancelButtonTitle:@"Annuler"
otherButtonTitles:nil];
[alert show];
}
}
Now, i would like to replace all my UIAlertView with an imageView ( show to the user a special UIImageView to tell him that there is an error ( connexion failure....), and remove this imageView when there is not server error.
Resume : I would like to show an imageView when the request fail and remove this image view and relance the request ( How I can do this with ASIHtppRequest) ?
Upvotes: 0
Views: 282
Reputation: 106
I think you can use a UIActionSheet to replace the UIAlertView because the ActionSheet can be handled like a UIView, so you can present the ActionSheet that contains your UIImageView. You can also use one of the buttons to dismiss the ActionSheet to reload your ASIHTTPRequest. The following code shows you the UIActionSheet's delegate methods that allow you to add your UIImageView and trigger your request when the cancel button is clicked.
#pragma -
#pragma ActionSheet Delegate
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
UIImageView * yourImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 55, 320, 100)];
//Configure yourImageView...
//Add picker to action sheet
[actionSheet addSubview:yourImageView];
// Release your yourImageView
[yourImageView release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [actionSheet cancelButtonIndex])
{
// Call back your ASIHTTPRequest
}
}
Don't forget to implement the UIActionSheetDelegate in your .h file.
Good luck.
Upvotes: 1