Ошибка запроса в ASIHttprequest - PullRequest
0 голосов
/ 30 марта 2012

Я использую ASIHttpRequest в моем проекте iOS. В 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];

    }    
}

Теперь я хотел бы заменить весь мой UIAlertView на imageView (показать пользователю специальный UIImageView, чтобы сообщить ему, что есть ошибка (сбой соединения ....), и удалить этот imageView, когда нет сервера ошибка.

Резюме: Я хотел бы показать imageView, когда запрос не выполнен, и удалить это представление изображения и повторно выполнить запрос (Как я могу сделать это с ASIHtppRequest)?

1 Ответ

1 голос
/ 30 марта 2012

Я думаю, что вы можете использовать UIActionSheet для замены UIAlertView, потому что ActionSheet может обрабатываться как UIView, поэтому вы можете представить ActionSheet, который содержит ваш UIImageView. Вы также можете использовать одну из кнопок, чтобы закрыть ActionSheet для перезагрузки ASIHTTPRequest. В следующем коде показаны методы делегирования UIActionSheet, позволяющие добавить свой 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
     }
}

Не забудьте внедрить UIActionSheetDelegate в ваш файл .h.

Удачи.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...