0

我创建了一个 NSURLConnection,并创建了一个单独的类用作委托,但连接完成后我无法使用委托数据。数据从委托类内部写入控制台,而不是外部。

在 ServerCommunicationDelegate 类(委托)中,在方法“connectionDidFinishLoading”中:

self.errorLog  = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
NSLog(self.errorLog); // Prints the data to console 

在发生连接的类中:

ServerCommunicationDelegate *del = [[ServerCommunicationDelegate alloc] init];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:del];
NSLog(@"Errorlog %@", del.errorLog); // Returns null

“errorLog”是“ServerCommunicationDelegate”的一个属性。

我对这里的委托范式有什么误解,还是我错过了其他什么?

无论哪种方式,提前谢谢。

4

1 回答 1

1

NSURLConnection异步工作。线

NSLog(@"Errorlog %@", del.errorLog); // Returns null

在连接完成加载之前执行(甚至可能在它开始加载之前)。

于 2013-07-04T08:52:17.520 回答