我正在使用 UITableView。如果没有网络连接,viewDidload 会抛出异常。我的 viewDidLoad 函数是:
 @try {
                NSLog(@"Request URL = %@",URLString);
                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL
                                                                  URLWithString:URLString]];
                NSData *response = [NSURLConnection sendSynchronousRequest:request
                                                     returningResponse:nil error:nil];
                NSError *jsonParsingError = nil;
                NSDictionary *tableData = [NSJSONSerialization JSONObjectWithData:response
                                                                      options:0
                                                                        error:&jsonParsingError];
                // Grab whole data with data field in JSON
                //    responseArray = [tableData objectForKey:@"data"];
                responseArray = [[NSMutableArray alloc]initWithArray:[tableData objectForKey:@"data"]];
                for(int i = 0; i < responseArray.count; i++)
                {
                    NSArray * tempArray = responseArray[i];
                    responseArray[i] = [tempArray mutableCopy];
                }
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                [btn setFrame:CGRectMake(280.0, 0.0, 40.0, 40.0)];
                [btn setImage:[UIImage imageNamed:@"sort_icon.png"] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(showActionSheet) forControlEvents:UIControlEventTouchUpInside];
                UIBarButtonItem *barbutton = [[UIBarButtonItem alloc]initWithCustomView:btn];
                self.navigationItem.rightBarButtonItem = barbutton;
        }
        @catch (NSException *exception)
        {
            exceptionOccured = YES;
            NSLog(@"Exception Ocurred");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error in connectivity" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }
在 cellForRowAtIndexPath 我这样做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @try {
    NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
    tempDict = [responseArray objectAtIndex:indexPath.row];
    return cell;
    }
    @catch (NSException *exception)
    {
        NSLog(@"Error in CEll Create");
        NSLog(@"Draw Alert");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error in connectivity" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}
在 AlertViewDelegate 函数中我正在做
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.navigationController popViewControllerAnimated:YES];
}
现在的问题是,每当出现异常并重新抛出异常并显示错误时,它都不会显示警报
Thread 1: EXC_BAD_ACCESS(code=2, address=0x2)
任何帮助将不胜感激...