我在iPhone上使用ASIHTTPRequest來調用服務器,然後發送包含JSON文件的響應。我在基本層面上開展工作,但是當我將它添加到我的項目並打電話給服務器時,我的應用程序開始與bad_access崩潰。iPhone上的ASIHTTPRequest問題(內存?)
我把從viewDidLoad中調用這樣:
requestModel = [[RequestModel alloc]init];
NSURL *url = [[NSURL URLWithString:@"myURL"]retain];
[requestModel eventsRequestFor:@"myUsername" password:@"myPassword" forURL:url];
這就要求在名爲RequestModel另一個類的函數,我經過,並試圖解開返回數組本身(大量的代碼):
-(void)eventsRequestFor:(NSString*)username password:(NSString*)password forURL:(NSURL*)forURL {
//use ASIHTTPRequest to post to sever. Here you authenticate and recieve answer
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:forURL];
[request setUsername:username];
[request setPassword:password];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request startAsynchronous];
[request release];
NSLog(@"Model called");
}
#pragma mark Model Delegates
- (void)uploadFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSLog(@"upload start");
NSString *stringFromRequest = [[NSString alloc]init];
stringFromRequest = [request responseString];
[self buildArrayFromRequest:stringFromRequest];
//[stringFromRequest release];
}
- (void)uploadFailed:(ASIHTTPRequest *)request {
NSString *statusMessage = [request responseStatusMessage];
NSLog(@"%@",statusMessage);
NSError *error = [request error];
NSLog(@"%@",error);
}
-(void)buildArrayFromRequest:(NSString*)string {
NSArray *arrayFromData = [[NSArray alloc]init];
arrayFromData = [string yajl_JSON];
NSLog(@"This is the array from the JSON %@",[arrayFromData objectAtIndex:0]);
NSMutableArray *events = [[NSMutableArray alloc] init];
for(int i= 0; i < [arrayFromData count];i++)
{
/////code to unpack array
}
///here i try to populate table with unpacked array
FirstViewController *firstVC = [[FirstViewController alloc]init];
[firstVC createTableWithArray:events];
[firstVC release];
[arrayFromData release];
[events release];
}
關於我要去哪裏的任何想法都是錯誤的?看起來我正在發佈一個已經發布的對象,但我找不到它。
你能後的調用堆棧(從調試器)以及好嗎? – deanWombourne 2011-01-21 17:56:12