我有這個函數調用函數來檢查CMS的信息。但UIActivityIndicatorView凍結直到檢查完成。不知道爲什麼。UIActivityIndicatorView freeze
編輯:有趣的事情之一,我註釋了performselector。 UIActivityIndicatorView仍然凍結。直到我拍了拍我的背按鈕,然後它開始打轉....
我使用的故事板,iOS 5的
-(void)showLoading
{
[activity startAnimating];
//loading is a label to show "File Loading"
loading.alpha =1;
//is a label to show a 0.3 alpha of the label
blackOverlay.hidden =0;
[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:2];
//[self updateFromInternet:@"a"];
}
-(void)updateFromInternet:(NSString *)urlStr
{
NSString *URLString = @"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml";
NSURL *updateDataURL = [NSURL URLWithString:URLString];
NSMutableURLRequest *WPXMLFetchRequest = [NSMutableURLRequest requestWithURL:updateDataURL];
self.receivedData = [NSMutableData data];
self.updateConnection = [NSURLConnection connectionWithRequest:WPXMLFetchRequest delegate:self];
NSLog(@"Checking update at : %@", updateDataURL);
//[self.updateConnection cancel];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
////NSlog(@"Receiving data");
[self.receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
////NSlog(@"Failed to receive data");
self.receivedData = nil;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
////NSlog(@"Received response from data");
[self.receivedData setLength:0];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *data=[[NSString alloc]initWithData:self.receivedData encoding:NSUTF8StringEncoding];
NSLog(@"data %@",data);
NSError *parseError = nil;
//NSDictionary *xmlDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];
self.receivedDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];
[self showDataOnScrollView];
}
「活動」是否開始然後凍結或只是保持凍結? – tipycalFlow 2012-03-01 12:34:18
它的理由凍結在那裏,在updateFromInternet被稱爲它開始 – Desmond 2012-03-01 12:37:13
評論引用後臺線程的含義是什麼?您不應該使用主線程以外的任何其他UIKit對象。但是你沒有顯示任何線程代碼。線程代碼是否在其他地方,或者你是否指向'performSelector:withObject:afterDelay:作爲後臺線程(它不是)? – Jim 2012-03-01 12:45:14