gpt4 book ai didi

iphone - ASIHTTPRequest异步请求在使用ARC时导致EXC_BAD_ACCESS

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:44 25 4
gpt4 key购买 nike

我正在使用 ARC(不,这不是 NDA)。

我有一个 TableView,在从 Delegate 调用的 didSelectRowAtIndexPath 方法中我创建了一个新对象,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]
}

在 NavigationController 顶部的对象中,我尝试异步创建 ASIHTTPRequest。请求开始后,我收到 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];
}

调用“startAsynchronous”方法后,状态栏中出现 NetworkActivity Indicator,但随后出现 EXC_BAD_ACCESS。如果我删除行

    request2.delegate = self;

有效,但我需要请求的结果!

我尝试使用 __strong 创建请求,但没有成功:

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

ASIFormDataRequest 类很好,因为在我分配 ArticleViewController 的带有 TableView 的父 View Controller 上,异步请求工作正常。

最佳答案

我解决了这个问题,我为 ArticleView 创建了一个 ivar,因此 viewController 不会被释放,委托(delegate)可以发送一些东西。

@property(strong) ArticleView *articleView;

感谢您的帮助!

关于iphone - ASIHTTPRequest异步请求在使用ARC时导致EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com