Objective c 未注意viewdidload中的说明
我正面临一个恼人的问题。我有一个应用程序,它基本上由几种方法组成: viewDidload,连接:didReceiveResponse,连接:didReceiveData 在我的viewDidload中,我为个人网站定义了一个NSURLRequest,并在它之后和之前添加了一个label.text=@“xxx”。我知道问题不在于IB中的标签链接,因为它用于显示我想要的内容 但现在这两个label.text指令似乎都不起作用,尽管我知道我的NSURLRequest有效,因为当我更改网站时,收到的字节数会发生变化。。。为什么呢?我猜后面的其他说明也不起作用 我会在可能的时候提供更多的细节,以防有人能在这方面给我启发 祝你今天愉快,谢谢你的帮助Objective c 未注意viewdidload中的说明,objective-c,ios,nsurlrequest,Objective C,Ios,Nsurlrequest,我正面临一个恼人的问题。我有一个应用程序,它基本上由几种方法组成: 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
我会将设置逻辑移到-viewwillbeen,而不是-viewDidLoad 没关系,我是通过将指令移动到另一个方法来实现这一点的。您可以提供一些代码的链接,或者将一些代码粘贴到此处,以便在分配值时查看/检查调试中的对象吗。它们可能为零,因此向它们发送消息将无效。好的,我用代码编辑了我的帖子。还有Vlad,我要检查一下。哦,我不认识Vlad,因为我的代码前面有一点(我没有发布它,因为它没有用)一个按钮按下的方法来更改我的label.text,它可以工作。我不能这样做,我的东西是主窗口,我没有任何视图。这就是他们所说的答案:S