gpt4 book ai didi

nsurlconnection - NSURLConnection 的 didReceiveData 方法中 appendData 的奇怪问题

转载 作者:行者123 更新时间:2023-12-04 20:45:12 27 4
gpt4 key购买 nike

我在植入简单的 NSURLConnection 时遇到了这个奇怪的问题...

调用了 didReceiveData 方法,我很乐意尝试附加接收数据,但是... nada!

肯定有一些数据(如长度所示,但 appendData 不附加数据!

我开始思考这个问题,我需要一些帮助,以免为时已晚:-)

这里有一些代码要看:

我的标题...

@interface ActionViewController : UITableViewController {
Site *site;

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

int nConnections;
BOOL fail;
}

我的实现..

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
NSLog(@"Received %d bytes of data",[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];
}

控制台输出...

[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

我不明白!帮助!!!

顺便说一句,数据是一个简单的 xml 结果,看起来像这样......

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

最佳答案

好吧,我在这个网站上关于 NSMutableData 的另一个问题中得到了答案。 ...忘记初始化了! (代码 18 或向 nil 发送消息的剩余部分是 Objective-C 的一个 NICE 特性)

receivedData = [[NSMutableData alloc] init];

关于nsurlconnection - NSURLConnection 的 didReceiveData 方法中 appendData 的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3539745/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com