开发者

Strange problem with appendData in didReceiveData method of NSURLConnection

I got this weird problem in implanting simple NSURLConnection...

The method didReceiveData get call and I'm happily trying to append the receive data but... nada!

There's some data for sure (as the length indicate but appendData do NOT append the data!

I start to bang my head on this one and I need some help before it's to late :-)

Here some code to look at :

My header...

@interface ActionViewController : UITableViewController {
 Site *site;

 NSURLConnection *siteConnection;
 NSMutableData *receivedData;
    UIView *waitView;
    UIActivityIndicatorView *activityIndicator;

 int nConnections;
    BOOL fail;
}

My implementation..

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    // Append the new data to receivedData.
 NSLog(@"Received %d bytes of d开发者_如何学运维ata",[data length]);
    [receivedData appendData:data];
 NSLog(@"Received %d bytes of data",[receivedData length]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);

 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
 [activityIndicator stopAnimating];
 waitView.hidden = YES;

    // release the connection
    [connection release];
}

The console output...

[Session started at 2010-08-21 21:27:55 -0400.]
2010-08-21 21:28:19.263 myApp[2042:207] Received 108 bytes of data
2010-08-21 21:28:19.263 myApp[2042:207] Received 0 bytes of data
2010-08-21 21:28:19.263 myApp[2042:207] Succeeded! Received 0 bytes of data

I don't get it! HELP!!!

BTW, the data is a simple xml result that look like this...

<donnee>0</donnee><donnee>0</donnee><donnee>0</donnee><donnee>1</donnee><donnee>0</donnee><donnee>0</donnee>


Well, got my answer in an another question on this site about NSMutableData... forgot to initialize the thing! (code 18 or a remainder of sending message to nil is a NICE feature of Objective-C)

receivedData = [[NSMutableData alloc] init];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜