2012-07-07 40 views
1

我是iPhone开发新手。我使用xcode 4.2。接收信号:EXC_BAD_ACCESS在web服务调用函数中

当我点击保存按钮,我从HTML页面获取值和我的Web服务正在处理它们,然后我得到的错误:

program received signal: EXC_BAD_ACCESS

在我的web服务调用功能。这里是我的代码:

 NSString *val=[WebviewObj stringByEvaluatingJavaScriptFromString:@"save()"]; 
    NSLog(@"return value:: %@",val); 
    [adict setObject:[NSString stringWithFormat:@"%i",userid5] forKey:@"iUser_Id" ]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:0] forKey:@"vImage_Url"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:1] forKey:@"IGenre_Id"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:2] forKey:@"vTrack_Name"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:3] forKey:@"vAlbum_Name"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:4] forKey:@"vMusic_Url"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:5] forKey:@"iTrack_Duration_min"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:6] forKey:@"iTrack_Duration_sec"]; 
    [adict setObject:[[val componentsSeparatedByString:@","]objectAtIndex:7] forKey:@"vDescription"]; 
    NSLog(@"dict==%@",[adict description]); 

    NSString *URL2= @"http://184.164.156.55/Music/Track.asmx/AddTrack"; 
    obj=[[UrlController alloc]init]; 
    obj.URL=URL2; 
    obj.InputParameters = adict; 
    [obj WebserviceCall]; 
obj.delegate= self; 

     //this is my function..it is working for so many function calls 
    -(void)WebserviceCall{ 


    webData = [[NSMutableData alloc] init]; 

    NSMutableURLRequest *urlRequest = [[ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString: URL ] ]; 

    NSString *httpBody = @""; 
     for(id key in InputParameters) 
     { 
     if([httpBody length] == 0){ 
     httpBody=[httpBody stringByAppendingFormat:@"&%@=%@",key,[InputParameters valueForKey:key]]; 
    } 
     else{ 
     httpBody=[httpBody stringByAppendingFormat:@"&%@=%@",key,[InputParameters valueForKey:key]]; 
      } 
      } 
     httpBody = [httpBody stringByAppendingFormat:httpBody];//Here i am getting EXC_BAD_ACCESS 

     [urlRequest setHTTPMethod: @"POST" ]; 
    [urlRequest setHTTPBody:[httpBody dataUsingEncoding:NSUTF8StringEncoding]]; 
    [urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; 


      NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; 



     } 

任何人都可以帮我吗?

由于事先

回答

1

stringByAppendingFormat期望一个(sprintf的样式)格式的字符串作为第一个参数,然后为每个%格式占位符更多的参数。例如:

[httpBody stringByAppendingFormat:@"Integer: %d, String: %@", 1234, @"Hello"]; 

如果您httpBody字符串恰好包含后跟有效的格式类型(例如“d”,“F”,“@”等)“%”,然后stringByAppendingFormat会希望额外论点,你没有提供。试图解引用这些参数会导致您的EXC_BAD_ACCESS。

我没有遵循你的代码的逻辑,所以我不确定你在那一行的实际意图。