花费太多时间从 RSS 提要加载新闻
Posted
技术标签:
【中文标题】花费太多时间从 RSS 提要加载新闻【英文标题】:Taking too much time in loading news from rss feed 【发布时间】:2013-05-13 11:19:14 【问题描述】:我正在使用新闻应用程序。我有六个不同的消息。我从 viewwillappear() 方法调用 rss 提要。我已经使用 selectedIndex 运行了一个开关盒。我包括了延迟加载,但从 rss 加载新闻仍然需要很长时间。 任何可能的解决方案? 提前致谢
(void)viewWillAppear:(BOOL)animated
[super viewWillAppear:YES];
noNewsLabel.hidden=YES;
bdNewsParser=[[[BDNewsParser alloc] init]retain];
if (loadingFlag==1)
ImgesName=[[NSMutableArray alloc] init];
dicImages_msg = [[NSMutableDictionary alloc] init];
if (loadingFlag!=2)
NSLog(@"newsTypeInd:%@",newsTypeInd);
[newsCat setText:[newsTypeInd objectAtIndex:selectedIndex]];
[newsTitleArray removeAllObjects];
[newsDescriptionArray removeAllObjects];
[newsLinkArray removeAllObjects];
[newsPublicationDate removeAllObjects];
[newsImageLinkArray removeAllObjects];
[newsSourceArray removeAllObjects];
switch(selectedIndex)
case 0:
[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/itnews.php"];
break;
case 1:
[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/internationalnews.php"];
break;
case 2:
// [bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/bangladeshnews.php"];
[self showAlert];
break;
case 3:
//[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/businessnews.php"];
[self showAlert];
break;
case 4:
[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/entertainmentnews.php"];
break;
case 5:
[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/sportnews.php"];
break;
default:
break;
newsTitleArray=bdNewsParser.titleArray;
newsDescriptionArray=bdNewsParser.descriptionArray;
newsLinkArray=bdNewsParser.linkArray;
newsPublicationDate=bdNewsParser.publicationDateArray;
newsImageLinkArray=bdNewsParser.newsImageArray;
newsSourceArray=bdNewsParser.newsSourceArray;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// [self filterArrayGroupWise:selectedIndex];
if ([newsTitleArray count]==0)
NSLog(@"Hide contrrol");
[self hideControls];
noNewsLabel.hidden=NO;
else
[self showControls];
noNewsLabel.hidden=YES;
[self setupScrollview];
ImgesName = newsImageLinkArray;
[self reloadScrolview];
savedTitleArr=[userDefault readArrayFromUserDefaults:@"FavoriteTitle"];
if (savedTitleArr)
if ([savedTitleArr containsObject:[newsTitleArray objectAtIndex:pageNo]])
[saveButton setEnabled:NO];
else
[saveButton setEnabled:YES];
else
[saveButton setEnabled:YES];
indicatorAnimatingFlag=0;
[activityView stopAnimating];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];
pageNo=0;
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * 0;
frame.origin.y = 0;
[scrollView setBounds:frame];
[bdNewsParser release];
index=0;
selectedIndex=0;
【问题讨论】:
【参考方案1】:您说“延迟加载”,但在哪里?在我看来,您拨打电话然后尝试访问其值:
case 0:
[bdNewsParser loadXMLByURL:@"http://amarhost.info/fuad/newsainment/itnews.php"];
break;
然后:
newsTitleArray=bdNewsParser.titleArray;
newsDescriptionArray=bdNewsParser.descriptionArray;
newsLinkArray=bdNewsParser.linkArray;
newsPublicationDate=bdNewsParser.publicationDateArray;
newsImageLinkArray=bdNewsParser.newsImageArray;
newsSourceArray=bdNewsParser.newsSourceArray;
【讨论】:
我没有给你具体的答案。只是指出你不是“延迟加载”任何东西。正确的术语是执行“异步任务”。 “懒加载”就是在你真正需要的时候做一些事情。 我采用了一个活动指示器,该指示器会在新闻和图像加载后进行动画处理,然后活动指示器就会停止。 [activityView startAnimating]; [activityView stopAnimating]; ** 最后我使用执行选择器解决了它 **- (void)viewWillAppear:(BOOL)animated indexNo=selectedIndex; newsCat.text=[newsTypeInd objectAtIndex:indexNo]; self.initialActivityIndicatorView.hidden=NO; [self.initialActivityIndicatorView startAnimating]; dateLabel.text=nil; [super viewWillAppear:YES]; [self performSelector:@selector(viewWillAppearForFlag0) withObject:nil afterDelay:0.5];
以上是关于花费太多时间从 RSS 提要加载新闻的主要内容,如果未能解决你的问题,请参考以下文章