簡體   English   中英

viewdidload中的說明未得到照顧

[英]Instructions in viewdidload not being taken care of

我面臨一個煩人的問題。 我有一個基本上由幾種方法組成的應用程序:viewDidload,connection:didReceiveResponse,connection: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。

沒關系,我通過將指令移至另一種方法來使其工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM