我有一个uicollectionView,当我选择一个单元格时,会加载一个新视图。内容是从集合视图中选择的图像,我可以在图像之间滚动。
我这样做但加载所选图像需要花费太多时间。
这就是我的表现:
- (void)passDataForward
{
PageViewController *secondViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]instantiateViewControllerWithIdentifier:@"page"];
secondViewController.data =tagsender;
secondViewController.imageArray=[[NSMutableArray alloc]initWithArray:imagesArray copyItems:YES];
secondViewController.delegate = self;
[self presentViewController:secondViewController animated:YES completion:^(void)
{
}];
}
in imagesArray我有图片的网址。
在我的新viewController中:
- (void)viewDidLoad
{
[super viewDidLoad];
for (int i = 0; i < [imageArray count]; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i+100;
frame.origin.y = 100;
frame.size = CGSizeMake(110.0, 120.0);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[imageArray objectAtIndex:i]]]];
dispatch_sync(dispatch_get_main_queue(), ^{
imageView.image=image;
});
});
[self.scrollView addSubview:imageView];
}