iphoneobjective-cxcodeasiformdatarequest

ASIHTTPRequest asynchronously request causes EXC_BAD_ACCESS when using ARC


I am using ARC (no, this is not NDA).

I Have a TableView, and in the didSelectRowAtIndexPath Method called from the Delegate I create a new Object, Subclass of UIViewController.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    NSDictionary *currentDict = [tableData objectAtIndex:indexPath.row];
    int articleID = [[currentDict objectForKey:@"id"] intValue];

    ArticleView *articleView = [[ArticleView alloc]initWithArticleID:articleID];
    articleView.delegate = self;
    articleView.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:articleView animated:YES]
}

In the Object what is on the top of the NavigationController I tried to make an ASIHTTPRequest asynchronously. After the request started I receive a EXC_BAD_ACCESS.

- (void)viewDidLoad {
    [super viewDidLoad];    
    ASIFormDataRequest *request2 = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:@"http://api.b....."]];
    request2.delegate = self;
    [request2 setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:articleID],@"article",nil]];
    [request2 addPostValue:@"getArticle" forKey:@"action"];
    [request2 addPostValue:[NSNumber numberWithInt:articleID] forKey:@"id"];
    [request2 startAsynchronous];
}

After I Call the "startAsynchronous" Method, the NetworkActivity Indicator in the Status Bar Appears, but then I get a EXC_BAD_ACCESS. If I remove the line

    request2.delegate = self;

it works, but I need the result of the request!

I tried to create the request with __strong, without success:

    ASIFormDataRequest __strong *request2 = [[ASIFormDataRequest alloc]initWithURL:[NSURL URLWithString:@"http://api.b....."]];

The ASIFormDataRequest Classes are fine, because on the parent View Controller with the TableView from where I allocate the ArticleViewController the asynchronously Request works fine.


Solution

  • I solved it, I made a ivar for the ArticleView, so the viewController doesn't get released and the delegate can send something.

    @property(strong) ArticleView *articleView;

    Thank you for your help!