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

!說明。 –

相關問題