Iphone I used [scrollView addSubView:imageView] but imageView doesn't appear

Iphone I used [scrollView addSubView:imageView] but imageView doesn't appear,iphone,objective-c,ipad,Iphone,Objective C,Ipad,I'm developing iPad app using SplitView. And I put UIScrollView in DetailView by using Interface Builder. Then I add IBOutlet UIScrollView scrollView; in detailViewController.h that was automatically created by Xcode. And connected this scrollView to UIScrollView in DetailView.xib . And I added below code to DetailViewController.m . - (void)viewDidLoad { [super viewDidLoad]; UIImageView *tempView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.jpg"]]; self.ima

I'm developing iPad app using SplitView. And I put UIScrollView in DetailView by using Interface Builder. Then I add

IBOutlet UIScrollView scrollView;
in detailViewController.h that was automatically created by Xcode. And connected this scrollView to UIScrollView in DetailView.xib .

And I added below code to DetailViewController.m .

- (void)viewDidLoad {  
    [super viewDidLoad];  
    UIImageView *tempView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.jpg"]];  
    self.imageView = tempView;  
    [tempView release];  
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);  
    scrollView.maximumZoomScale = 4.0;  
    scrollView.minimumZoomScale = 0.75;  
    scrollView.clipsToBounds = YES;  
    scrollView.delegate = self;  
    [scrollView addSubView:imageView];
    [imageView release];
}

I think by add this code, scrollable image is shown in detailView. But nothings appear.

Please teach me how to display UIScrollView in detailView.


#1

Try setting the frame property, like this:

tempView.frame = CGRectMake(0, 0, 100, 100); //x, y, width, height

Also, why are you first creating a tempView, then point self.imageView to it, and then release them both in the end? Wouldn't it be more readable and maintainable to just skip the self.imageView and just use tempView?


#2

Add the UIScrollView delegate and return the imageView. This will help in handling the resizing the image

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imgView;
}