新建一个single View Application的工程,再建一个类,专门用来实现HTTP请求数据的功能
如下,只写了一个函数实现异步调用
-(void) postDataInfo:(NSString*) nsPostVar:(NSString*)nsUrl:(NSString*)nsReferer
{
    NSData *postData = [nsPostVar dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];  
    
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];  
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  
    [request setURL:[NSURL URLWithString:nsUrl]];  
    
    [request setHTTPMethod:@"POST"]; 
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];  
    [request setValue:nsReferer forHTTPHeaderField:@"Referer"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];  
    [request setHTTPBody:postData];  
    
    
   
    self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate     App].viewController];  //异步处理,委托主View接受信息
    
    
}
主view中
//全部数据接收完毕时触发
- (void)connectionDidFinishLoading:(NSURLConnection *)aConn
{
    NSLog(@"connectionDidFinishLoading");
}另外新建了一个view,专门来显示数据
在这个viewController中,我新建了2个timer来调用 postDataInfo
如下
- (void)postWonMoney
{
    [[AppDelegate App].viewController.pwebOperator postDataInfo:参数1:参数2:参数3];
  
}
/////////////////view显示的时候就执行这个timer
[NSTimer scheduledTimerWithTimeInterval:(1) target:self selector:@selector(responseInfoTimer) userInfo:nil repeats:YES];
- (void)responseInfoTimer{
  [self postWonMoney];//此处调用可以成功,能得到HTTP请求的数据
  //如果此处再设定一个定时器,如下
  [NSTimer scheduledTimerWithTimeInterval:(5) target:self selector:@selector(responseInfoTimer2) userInfo:nil repeats:YES];
}
- (void)responseInfoTimer2{
  [self postWonMoney];//此处调用不成功,能得到HTTP请求的数据
  //程序执行完self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate     App].viewController]; 就崩溃了
}
请问这是什么原因,为什么在第一个定时器那里执行是没有问题的呢

解决方案 »

  1.   

    崩溃后程序调到这里
    @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
    后面提示Thread 1:EXC_BREAKPOINT(code=EXC_I386_BPT,subcode=0x0)
    命令行无任何提示
      

  2.   

    执行完
    self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
    在接收的函数
    //全部数据接收完毕时触发
    - (void)connectionDidFinishLoading:(NSURLConnection *)aConn
    {
      NSLog(@"connectionDidFinishLoading");
    }没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
      

  3.   

    执行完
    self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController];
    在接收的函数
    //全部数据接收完毕时触发
    - (void)connectionDidFinishLoading:(NSURLConnection *)aConn
    {
      NSLog(@"connectionDidFinishLoading");
    }没有执行的时候就报错了,是不是委托那里有问题,在TIMER里面再建立一个TIMER,然后第二个TIMER的执行函数里面去调用就会出问题,如果只是一个TIMER,然后在这个TIMER的执行函数里面去调用是没有问题的
      

  4.   

    让奔溃信息给的更全些,参考这个:http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode
      

  5.   

    可能是过度释放引起的。
    需要输出更多的调试信息,参考:
    http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode
    http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombieenabled-in-xcode-4
    http://blog.csdn.net/linzhiji/article/details/6771998
      

  6.   

    命令行给出的提示是这个
    -[CFRunLoopTimer release]: message sent to deallocated instance 0x162ac330
      

  7.   

    那问题已经清楚了。就是释放了,已经被释放的对象,俗称“僵尸对象”。看看那几个 Timer 的申请与释放。
      

  8.   

     self.Info = [[NSURLConnection alloc] initWithRequest:request delegate:[AppDelegate App].viewController]; //异步处理,委托主View接受信息这个每次赋值的时候会把前面一个Info release,而前面那个info的请求还在执行,就会出问题。
    建议赋值前先self.info调用一下cancel。
      

  9.   

    恩,对的,我按照前辈的提示,查看到CFRunLoopTimer release的错误 ,就去找TIMER的问题,果然是这里的问题,第二个TIMER赋值的时候一定要self.第二个TIMER的对象=XXXX,这样就没有问题了
    前辈能否再帮我看看这个显示的问题,多谢了,晚上来接贴
    http://www.cocoachina.com/bbs/read.php?tid=112855&page=1#670884