在集合视图上加载叠加层

时间:2014-10-31 21:40:21

标签: ios objective-c uicollectionview xcode6

我有一个加载视图,我在视图的顶部插入,同时它使用一个单独的线程解析来自互联网的数据,在这种情况下它位于UICollectionView之上。

由于某种原因,我无法理解加载覆盖在其自己的whist上消失,解析仍在进行,呈现一两秒的空白屏幕。在UIcollectionviews上,它似乎不会发生在UITableViews上。任何帮助将不胜感激。

活动overlay.m:

#import "ActivityOverlayController.h
@interface ActivityOverlayController ()

@end

@implementation ActivityOverlayController

-(id)initWithFrame:(CGRect)theFrame {
if (self = [super init]) {
    frame = theFrame;
    self.view.frame = theFrame;
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad]; 
NSLog(@"%@", @"ActivityOverlayController called");
container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 30)];
activityLabel = [[UILabel alloc] init];
activityLabel.text = NSLocalizedString(@"Loading", @"string1");
activityLabel.textColor = [UIColor lightGrayColor];
activityLabel.font = [UIFont boldSystemFontOfSize:17];
[container addSubview:activityLabel];
activityLabel.frame = CGRectMake(0, 3, 70, 25);
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator.color = [UIColor blackColor];
activityIndicator.hidesWhenStopped = TRUE;
[activityIndicator startAnimating];
activityIndicator.frame = CGRectMake(80, 0, 30, 30);
[container addSubview:activityIndicator];
[self.view addSubview:container];
container.center = CGPointMake(frame.size.width/2, frame.size.height/2);
self.view.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.7];
}
-(void)viewWillAppear:(BOOL) animated {
[super viewWillAppear:animated];
}
-(void)viewWillDisappear:(BOOL) animated {
[super viewWillDisappear:animated];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[activityIndicator stopAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

解析collectionViewController.m的一部分:

-(void)ParseCollectionView{

    [self performSelectorOnMainThread:@selector(showActivityView) withObject:nil waitUntilDone:YES];

    CollectionViewImages = [[NSMutableArray alloc]init];
    NSData *xmlData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:GalleryTitle]];
    cvTBXML = [[TBXML alloc]initWithXMLData:xmlData];

    // Obtain root element


    TBXMLElement * root = cvTBXML.rootXMLElement;
    TBXMLElement * channel = [TBXML childElementNamed:@"channel" parentElement:root];
    if (root)
    {
        TBXMLElement * item = [TBXML childElementNamed:@"item" parentElement:channel];
        while (item !=nil)
        {


            //create new instance of news object
            NSObject *Imagetoparse = [[GalleryImage alloc] init];

            TBXMLElement * link = [TBXML childElementNamed:@"link" parentElement:item];
            NSString *linktext= [TBXML textForElement:link];

            [Imagetoparse setValue:linktext forKey:@"link"];

            TBXMLElement * thumbnail = [TBXML childElementNamed:@"description" parentElement:item];
            NSString *Thumbnailtext= [TBXML textForElement:thumbnail];

            Thumbnailtext = [Thumbnailtext substringFromIndex:21];
            NSInteger *slength = Thumbnailtext.length -4;
            Thumbnailtext = [Thumbnailtext substringToIndex:slength];

            Thumbnailtext = [Thumbnailtext stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
            Thumbnailtext = [Thumbnailtext stringByReplacingOccurrencesOfString:@"thumb" withString:@"main"];

            NSLog(@"Thumnail1 : %@", Thumbnailtext);

            NSData *Thumbnailimage = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: Thumbnailtext]];

            [Imagetoparse setValue:Thumbnailimage forKey:@"thumbnail"];

            [CollectionViewImages addObject:Imagetoparse];
            item = [TBXML nextSiblingNamed:@"item" searchFromElement:item];

        }
    }


    [self.collectionView reloadData];

    NSLog(@"%@", @"Finished Parse Collection View");
    [self performSelectorOnMainThread:@selector(hideActivityView) withObject:nil waitUntilDone:NO];
}

-(void)showActivityView {
    if (overlayController == nil) {
        overlayController = [[ActivityOverlayController alloc] initWithFrame:(self.view.superview.bounds)];

    }
    [self.view.superview insertSubview:overlayController.view aboveSubview:self.view];
}

-(void)hideActivityView {
    [overlayController.view removeFromSuperview];
}

0 个答案:

没有答案
相关问题