我有这个函数调用函数来检查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