As a newbie to iOS programming I was a bit confused about UIImageView and UIScrollView when working inside UIPopoverController. Here they are...
A UIViewController whose view point to an UIScrollView whose subview is an UIImageView. The UIImageView's image property is set by another class during UIViewController initialization.
-(void)loadView{
self.scrollView=[[UIScrollView alloc]init];
self.imageView=[[UIImageView alloc]init];
self.imageView.contentMode=UIViewContentModeScaleAspectFit;
[self.scrollView addSubview:self.imageView];
self.view=self.scrollView;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.imageView.image=self.image;
self.scrollView.contentSize=self.imageView.image.size;
}
Then I put the UIViewController as contentViewController of a UIPopoverController which is then pop up in response block.
cell.actionBlock=^{
NSLog(@"Going to show image for %@", item);
BNRItemCell* strongCell=weakCell;
if([UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad){
NSString* itemKey=item.itemKey;
UIImage* img=[[BNRImageStore sharedStore]imageForKey:itemKey];
if(!img){
return;
}
CGRect rect=[self.view convertRect:strongCell.thumbnailView.bounds fromView:strongCell.thumbnailView];
BNRImageViewController* ivc=[[BNRImageViewController alloc]init];
ivc.image=img;
self.imagePopover=[[UIPopoverController alloc]initWithContentViewController:ivc];
self.imagePopover.delegate=self;
self.imagePopover.popoverContentSize=CGSizeMake(600,600);
[self.imagePopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
};
When the block runs a Popup window shows up but no image shows, which I am sure image is properly set and contentSize of UIScrollView is also set up as image size.
When I change UIViewController's view to UIImageView directly, the image shows. I'm not sure what happens and why image in scrollview is not visible.