我想编写一些代码来处理HTTP连接失败时的异常。我使用下面的代码:如何在iPhone上的HTTP连接失败时弹出警报?
-(void) connection:(NSURLConnection *)connection
didFailWithError: (NSError *)error {
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle: [error localizedDescription]
message: [error localizedFailureReason]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
[activityIndicator stopAnimating];
NSLog (@"Connection Failed with Error");
}
但是,程序只是在连接失败时崩溃。如何让警报弹出而不会导致程序崩溃?
这是在主线程还是在后台线程中运行?在后台线程中操作UI *对象往往不起作用。除此之外,坠毁事件发生在哪条线上?使用调试器或移动NSLog线查找。 – 2009-03-03 12:22:09