gpt4 book ai didi

objective-c - viewdidload 中的指令未被处理

转载 作者:行者123 更新时间:2023-11-29 05:00:13 25 4
gpt4 key购买 nike

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

在我的 viewDidload 中,我定义了一个指向个人网站的 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

最佳答案

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

关于objective-c - viewdidload 中的指令未被处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7163418/

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