viewdidload 中的指令未被处理

发布于 2024-12-01 03:47:13 字数 1811 浏览 0 评论 0原文

我面临着一个恼人的问题。我有一个应用程序,它基本上由几种方法组成: viewDidload、connection:didReceiveResponse、connection:didReceiveData...

在 vi​​ewDidload 中,我定义了一个到个人网站的 NSURLRequest,并在其前后添加了一个 label.text=@"xxx"。我知道问题不是来自链接 IB 中的标签,因为它曾经显示我想要的内容。

但现在似乎这两个 label.text 指令都不起作用,即使我知道我的 NSURLRequest 有效,因为当我更改网站时收到的字节数发生了变化......为什么会这样?我猜后面的其他指令也不起作用。

我会尽可能提供更多细节,以防有人能启发我。

祝您有美好的一天,感谢您的帮助

- (void)viewDidLoad {
 [super viewDidLoad];
 label.text=@"rrr";

request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mywebsite.aspx?example=5"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
label.text=@"aeza";

 NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

if (connection) {
    receiveddata=[[NSMutableData data] retain];
    label.text=@"NO BUG";
}
else {
label.text=@"BUG";
}
datastring = [[NSString alloc] initWithData:receiveddata encoding:NSUTF8StringEncoding];

components=[datastring componentsSeparatedByString:@"|"];

label.text=datastring;
[datastring release];
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse       *)response
{
[receiveddata setLength:0];
}

-(void) connection: (NSURLConnection *)connection didReceiveData: (NSData *)data
{
[receiveddata appendData:data];
}

-(void)connection: (NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[receiveddata release];
NSLog(@"Connection failed! Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received %d bytes of data",[receiveddata length]);
[connection release];
[receiveddata release];
}
@end

I am facing an annoying problem. I have an application who is basicly made of several methods:
viewDidload, connection:didReceiveResponse, connection:didReceiveData...

In my viewDidload, I define a NSURLRequest to a personal websiten, and right after and before it I added a label.text=@"xxx". I know the problem doesn't come from linking the label in IB because it used to display what I wanted.

But now it seems none of those two label.text instructions are working even though I know my NSURLRequest works because the number of bytes received changes when I change the website... Why is that ? And I'm guessing the other instructions that come after aren't working either.

I will give more details when I can in case anyone can enlighten me on this.

Have a good day and thanks for your help

- (void)viewDidLoad {
 [super viewDidLoad];
 label.text=@"rrr";

request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mywebsite.aspx?example=5"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; 
label.text=@"aeza";

 NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

if (connection) {
    receiveddata=[[NSMutableData data] retain];
    label.text=@"NO BUG";
}
else {
label.text=@"BUG";
}
datastring = [[NSString alloc] initWithData:receiveddata encoding:NSUTF8StringEncoding];

components=[datastring componentsSeparatedByString:@"|"];

label.text=datastring;
[datastring release];
}

-(void) connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse       *)response
{
[receiveddata setLength:0];
}

-(void) connection: (NSURLConnection *)connection didReceiveData: (NSData *)data
{
[receiveddata appendData:data];
}

-(void)connection: (NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[receiveddata release];
NSLog(@"Connection failed! Error - %@ %@",
      [error localizedDescription],
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received %d bytes of data",[receiveddata length]);
[connection release];
[receiveddata release];
}
@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗫嚅 2024-12-08 03:47:13

我会将设置逻辑移至 -viewWillAppear,而不是 -viewDidLoad。

I would move that setup logic to -viewWillAppear, rather than the -viewDidLoad.

冬天旳寂寞 2024-12-08 03:47:13

没关系,我通过将指令转移到另一种方法来使其发挥作用。

Nevermind, I got this to work by moving instructions to another method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文