我在UICollectionView中显示文章,并带有一个按钮,用于打开WYPopoverController,用户可以放大图像。
为避免两次下载图像,我试图将图像从UICollectionView传递到popover,但它无法正常工作:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
LOArcticlesCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
[cell.imageView setImageWithURL:[NSURL URLWithString:[[articlesArray objectAtIndex:indexPath.row]objectForKey:@"photoUrl"]]placeholderImage:[UIImage imageNamed:@"simboloLakari29.png"]];
index= indexPath.row;
self.imageArticle = cell.imageView.image;
self.imageUrl = [NSString stringWithString:[[articlesArray objectAtIndex:indexPath.row]objectForKey:@"photoUrl"]];
cell.lblMake.text = [NSString stringWithString:[[articlesArray objectAtIndex:indexPath.row]objectForKey:@"marca"]];
cell.lblMake.lineBreakMode = NSLineBreakByWordWrapping;
cell.lblModel.text = [NSString stringWithString:[[articlesArray objectAtIndex:indexPath.row]objectForKey:@"modelo"]];
cell.lblModel.lineBreakMode = NSLineBreakByWordWrapping;
cell.lblPrice.text = [NSString stringWithString:[[articlesArray objectAtIndex:indexPath.row]objectForKey:@"precio"]];
cell.lblOrder.text = [NSString stringWithFormat:@"%ld de %ld", (unsigned long)indexPath.row+1, (unsigned long)articlesArray.count];
//button magnify position
CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
if (screenHeight == 568) {
cell.magnify.frame = CGRectMake(145.0, 418.0, 30.0, 30.0);
cell.imageView.frame = CGRectMake(20.0, 45.0, 260.0, 260.0);
}
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"biggerPicture"])
{
WYStoryboardPopoverSegue* popoverSegue = (WYStoryboardPopoverSegue*)segue;
LOBiggerPictureViewController* destinationViewController = (LOBiggerPictureViewController *)segue.destinationViewController;
destinationViewController.preferredContentSize = CGSizeMake(320, 320);
destinationViewController.imageDownloaded = self.imageArticle;
popoverController = [popoverSegue popoverControllerWithSender:sender permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
WYPopoverBackgroundView* appearance = [WYPopoverBackgroundView appearance];
[appearance setTintColor:[UIColor redColor]];
UIColor* popColor = [UIColor colorWithRed:126/255.0 green:34/255.0 blue:110/255.0 alpha:1.0];
WYPopoverBackgroundView* popoverAppearance = [WYPopoverBackgroundView appearance];
[popoverAppearance setOuterCornerRadius:4];
[popoverAppearance setOuterShadowBlurRadius:1];
[popoverAppearance setOuterShadowColor:[UIColor darkGrayColor]];
[popoverAppearance setOuterShadowOffset:CGSizeMake(1, 1)];
[popoverAppearance setGlossShadowColor:[UIColor lightGrayColor]];
[popoverAppearance setGlossShadowOffset:CGSizeMake(1, 1)];
[popoverAppearance setBorderWidth:8];
[popoverAppearance setArrowHeight:10];
[popoverAppearance setArrowBase:20];
[popoverAppearance setInnerCornerRadius:4];
[popoverAppearance setInnerShadowBlurRadius:0];
[popoverAppearance setInnerShadowColor:[UIColor darkTextColor]];
[popoverAppearance setInnerShadowOffset:CGSizeMake(1, 1)];
[popoverAppearance setFillTopColor:popColor];
[popoverAppearance setFillBottomColor:popColor];
[popoverAppearance setOuterStrokeColor:popColor];
[popoverAppearance setInnerStrokeColor:popColor];
UINavigationBar* navBarInPopoverAppearance = [UINavigationBar appearanceWhenContainedIn:[UINavigationController class], [WYPopoverController class], nil];
[navBarInPopoverAppearance setTitleTextAttributes: @{
NSForegroundColorAttributeName : [UIColor clearColor],
NSShadowAttributeName : [UIColor lightGrayColor],
NSShadowAttributeName : [NSValue valueWithUIOffset:UIOffsetMake(0, -1)]}];
}
}
在popover中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:imageDownloaded waitUntilDone:YES];
[self.imageView sizeToFit];
self.scrollView.contentSize =self.image.size;
self.scrollView.delegate = self;
self.scrollView.minimumZoomScale = 1.0;
self.scrollView.maximumZoomScale = 3.0;
}
NSLog显示一个空对象。有什么问题?
答案 0 :(得分:0)
故事板中的弹出窗口在Xcode 6中有点被弃用。首先要检查的是你的弹出窗口,看看“segue”下拉是否显示为“Popover”或“Present as Popover”。我相信“Popover”有些东西在iOS8上已经停止正常工作。
如果您的应用能够使用,只需将其更改为“呈现为弹出窗口”即可解决此问题。如果您没有该选项,请检查故事板(第一个选项卡)的“文件检查器”部分中的“使用大小类”框,以启用新的弹出窗口。
答案 1 :(得分:0)
尝试在 viewWillAppear 中设置图像,而不是 viewDidLoad 。我认为该变量尚未由 prepareforSegue 设置。