gpt4 book ai didi

objective-c - ASIHttprequest 请求失败

转载 作者:行者123 更新时间:2023-11-29 04:43:53 25 4
gpt4 key购买 nike

我在我的 iOS 项目中使用 ASIHttpRequest。在 requestFail 中我这样做:

#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];

}
}

现在,我想用 imageView 替换所有 UIAlertView (向用户显示一个特殊的 UIImageView 告诉他有错误(连接失败......),并在没有服务器时删除此 imageView错误。

恢复:我想在请求失败时显示一个 imageView 并删除此 ImageView 并重新请求(我如何使用 ASIHtppRequest 来做到这一点)?

最佳答案

我认为您可以使用 UIActionSheet 来替换 UIAlertView,因为 ActionSheet 可以像 UIView 一样处理,因此您可以呈现包含 UIImageView 的 ActionSheet。您还可以使用其中一个按钮来关闭 ActionSheet 以重新加载 ASIHTTPRequest。以下代码向您展示了 UIActionSheet 的委托(delegate)方法,这些方法允许您添加 UIImageView 并在单击取消按钮时触发您的请求。

#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
}
}

不要忘记在 .h 文件中实现 UIActionSheetDelegate。

祝你好运。

关于objective-c - ASIHttprequest 请求失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9942985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com