3

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.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
brokedid
  • 879
  • 2
  • 10
  • 35
  • Try using this instead:[request setDelegate:self]; Also if you are displaying the content on the view your just "loaded" you will want to do this synhcronously or have something to detect the async finished and refresh the view. – Joe Coder Aug 18 '11 at 17:06
  • 2
    You may need to add an ivar to reference the request and keep it in memory. However I'm not sure why it would work if you don't set the delegate. – jtbandes Aug 18 '11 at 17:17
  • Using this: [request setDelegate:self] also fails. Because of this I need the Delegate to check when the request is done. Instead I show a loading view, so the other Tabs of my TabBar Applications can be accessed while the request is loading. But there must be a way to get the asynchronously request working? – brokedid Aug 18 '11 at 17:17
  • 1
    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! – brokedid Aug 18 '11 at 19:26
  • 3
    Please write that as an answer and accept it. – steipete Aug 19 '11 at 09:09
  • I've solved it via ivar, but one problem I have: When I call [request clearDelegateAndCancel] the request didn't stop (I see it in the loading indicator) – brokedid Nov 03 '11 at 17:13

1 Answers1

1

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!

brokedid
  • 879
  • 2
  • 10
  • 35