ios - 接收信号 : EXC_BAD_ACCESS in web service call function

标签 ios xcode xcode4.2

我是 iPhone 开发新手。我正在使用 xcode 4.2。

当我点击保存按钮时,我从 html 页面获取值并且我的网络服务正在处理它们,然后我收到错误:

program received signal: EXC_BAD_ACCESS

在我的网络服务调用函数中。这是我的代码:

     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];



       }

谁能帮帮我?

提前致谢

最佳答案

stringByAppendingFormat 需要一个(sprintf 样式)格式化字符串作为它的第一个参数,然后是每个 % 格式占位符的另一个参数。例如:

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

如果您的 httpBody 字符串恰好包含一个 '%' 后跟一个有效的格式类型(例如 'd'、'f'、'@' 等),那么 stringByAppendingFormat 将需要您未提供的额外参数。尝试取消引用这些参数将导致您的 EXC_BAD_ACCESS。

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

关于ios - 接收信号 : EXC_BAD_ACCESS in web service call function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11373958/

相关文章:

ios - 如何检查滑动是否在堆栈 View 的范围内

ios - 在 UIStoryBoard 上使用 UISearchDisplayController 时无单元格

javascript - 处理 iOS 虚拟键盘 “previous” , “next” , “Go/Enter” 按钮

ios - 如何在任务切换器中显示锁定屏幕并正确恢复

ios - 在 WatchKit 中使用应用内购买功能来获得一目了然的功能和复杂功能

objective-c - 在 Xcode 调试器中检查数组的内容

ios - UITabBarViewController 的自定义 TabBar 布局

xcode - XCode 4 中的 header 搜索路径

iphone - 如何隐藏数字小键盘?

crash - 崩溃日志-SIGTRAP-使用XCode 4.2的iPhone模拟器