1

我有一个 tableView 控制器来加载我解析的 XML 数据。这需要一些时间来完成。

- (void)viewDidLoad
{
[super viewDidLoad];

CustomStringParser *customStringParser = [[CustomStringParser alloc] init];

// Set MORE logo in navigation bar
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Navigation"]];

// Download and parse XML data
RXMLElement *rxml = [RXMLElement elementFromXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.morecobalt.co.uk/rss/?t=events"]]];

// Create an array to store each feed
eventsFeeds = [[NSMutableArray alloc] init];

// Loop through XML data
[rxml iterate:@"channel" usingBlock:^(RXMLElement *supportElement) {
    [supportElement iterate:@"item" usingBlock:^(RXMLElement *repElement) {

        // Assign element to string
        NSString *title = [repElement child:@"title"].text;
        NSString *subtitle = [repElement child:@"tagline"].text;
        NSString *description = [repElement child:@"description"].text;
        NSString *imageurl = [repElement child:@"image"].text;
        NSString *startDate = [repElement child:@"start_date"].text;
        NSString *endDate = [repElement child:@"end_date"].text;

        // Assign element value to MoreCobalt.h propertys
        currentFeed = [MoreCobaltEvents alloc];
        currentFeed.title = title;
        currentFeed.subtitle = subtitle;
        currentFeed.imageurl = imageurl;

        // DESCRIPTION FORMATTING
        description = [customStringParser parseHTML:description];
        description = [customStringParser parseLinesMultiple:description];
        description = [customStringParser removeSocialSignifiers:description];
        currentFeed.description = description;

        // DATE FORMATTING
        currentFeed.startDate = [customStringParser formatDate:startDate];
        currentFeed.endDate = [customStringParser formatDate:endDate];

        // Add a new object to the feeds array
        [eventsFeeds addObject:currentFeed];
    }];
}];
}

在解析数据时,我想添加一个带有活动指示器的加载屏幕。我猜这将是一个子视图。我怎样才能做到这一点?

注意:我使用故事板。下图

在此处输入图像描述

4

2 回答 2

2

只需在您的 xib 上拖动一个活动指示器组件。在 .h 文件中声明一个属性。把它挂起来。

在 viewDidLoad 调用中的 .m 文件中。

[self.activityIndicator starAnimating];
[self.activityIndicator.hidesWhenStopped = YES;

然后在你的表加载后调用:

[self.activityIndicator stopAnimating];

不需要子视图。

于 2013-10-31T12:14:56.880 回答
-1
Write below code in **AppDelegate.h** 
 UIActivityIndicatorView *progressIndicator;
    UIView *progressIndicatorView;


Write below code in **AppDelegate.m** 

-(void) addProgressIndicator:(UIView *)parentView
{
    [self.progressIndicatorView removeFromSuperview];

        self.progressIndicatorView = [[UIView alloc] initWithFrame:CGRectMake(0,0, parentView.frame.size.width,parentView.frame.size.height)];

        self.progressIndicatorView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        self.progressIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake((parentView.frame.size.width - 70) / 2,(parentView.frame.size.height - 70) / 2,70,70)];

    [self.progressIndicatorView addSubview:self.progressIndicator];
    [parentView addSubview:self.progressIndicatorView];
    [parentView bringSubviewToFront:self.progressIndicatorView];
    [self.progressIndicatorView bringSubviewToFront:self.progressIndicator];
    [self.progressIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [self.progressIndicator setHidesWhenStopped:YES];
    [self.progressIndicator stopAnimating];
    [self.progressIndicatorView setHidden:YES];
}

-(void) startProgressIndicator
{
    [NSThread detachNewThreadSelector:@selector(showProgressIndicator) toTarget:self withObject:nil];
}

-(void) showProgressIndicator
{
    [self.progressIndicatorView setHidden:NO];
    [self.progressIndicator startAnimating];
}

-(void) stopProgressIndicator
{
    [self.progressIndicator stopAnimating];
    [self.progressIndicatorView setHidden:YES];
}

在 viewDidLoad/ViewWillAppear 中,在要显示进度指示器的地方调用此方法。祝你好运 !!

于 2013-10-31T12:19:43.653 回答