1

我有一个tableView控制器加载我解析的XML数据。这需要一些时间去做。在tableview显示前添加加载视图控制器

- (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]; 
    }]; 
}]; 
} 

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

注:我使用故事板。下面

enter image description here

回答

2

图片上的厦门国际银行只需拖动活动指标组成。 在.h文件中声明一个属性。把它挂起来。

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

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

再经过你的表负荷拨打:

[self.activityIndicator stopAnimating]; 

无需子视图。

+0

我无法添加活动指标在tableview的中间。它会自动放置在我的细胞下方。这不是我想要的。谢谢 – user2920762

+0

如果你在其中加入正确的约束,它可以:-)你可以在你的界面上放置任何你想要的东西。 –

+0

约束似乎被锁定。 – user2920762

-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中调用您希望显示进度指示器的方法。 祝你好运!

+0

!说明。 –

相关问题