从rss feed加载新闻需要花费太多时间

时间:2013-05-13 11:19:15

标签: iphone ios ios4

我正在使用新闻应用。我有六个不同的消息。我从viewwillappear()方法调用rss提要。我用selectedIndex运行了一个switch case。我包括延迟加载,但仍然需要花费大量时间从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 个答案:

答案 0 :(得分:0)

你说“懒加载”,但在哪里?在我看来,你打电话,然后你试图访问它的价值:

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;