views:

731

answers:

2

I am a noob at OBJ-C :)

I am trying to add a UIImageView to a UIScrollView to display a large image in my iPhone app.

I have followed the tutorial here exactly:

http://howtomakeiphoneapps.com/2009/12/how-to-use-uiscrollview-in-your-iphone-app/

The only difference is that in my App the View is in a seperate tab and I am using a different image.

here is my code:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Cheyenne81"]];
    self.imageView = tempImageView;
    [tempImageView 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];
}

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

and:

@interface UseScrollViewViewController : UIViewController<UIScrollViewDelegate>{
    IBOutlet UIScrollView *scrollView;
    UIImageView *imageView;
}

@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *imageView;

@end

I then create a UIScrollView in Interface Builder and link it to the scrollView outlet. Thats when I get the problem. When I run the program it crashes instantly. If I run it without linking the scrollView to the outlet, it will run (allbeit with a blnk screen).

The following is the error I get in the console:

2010-03-27 20:18:13.467 UseScrollViewViewController[7421:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4a179b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key scrollView.'

A: 

First, the obligatory "the iPad SDK is still under NDA, so you shouldn't be posting this question here, and we can't help you" response.

Now If this were and iPhone app I would say check in the interface builder: click on "File's owner" and in the inspector, make sure that the class is set to be the class you are using to load the nib.

Eric Schweichler
it is an iPhone app, i dont know what you're talking about ;)Thank you for the response, there is only one connection to speak of, right? I connected the scrollView in IB to the scrollView outlet by control+click dragging from the UIScrollView to File's Owner and selected the "scrollView" outlet.Is there something else I should be doing? (I'm very new to this so I'm sure this is a very obvious error on my part)
Brodie
see edit in answer above.
Eric Schweichler
I checked and file's owner was set to the class in which the above listed code comes from. Shouldnt the class for this file's owner be set to the class that contains all the above code? This is a tab view app. Either way I tried changing the class to firstResponder as well as the AppDelegate and I still got the same crash as soon as I loaded the app.
Brodie
Have you had any luck with this?Normally there are two problems I've encountered that can cause this error.1) the class of Files owner is not set in IB, or it's set to a class that doesn't have the proper outlets for my nib.2) the outlet names don't match between the nib and class files, usually this is caused by typos. ;)
Eric Schweichler
no luck yet, i have checked and rechecked, the re-wrote the entire thing just to make sure. Could it have to do with the fact that the view in my project is part of a tab view application, and the one in the example is a stand alone?....What calss needs to be in file's owner? The one where all the code is right?
Brodie
could the class in the MainWindow File's Owner be incorrect? It was just set to UIView...i tried switching it to app delegate and first responder...no luck...now i think im just screwing it up trying to find the problem
Brodie
never mind...because the error only occurs when I link the UIScrollView to the scrollView outlet...
Brodie
The class of the files owner should be the class that is the controller for the nib you are loading. so, for example, in my app, I create my tabbar in my app delegate and there is no nib associated with it since I create it only in code. then for each of my views I create a UINavigationController (again in code) and add them to the tab bar, each navigation controller starts with a view that contains a UITableView controller, which has an associated nib file who's file's owner class is the controller for these UITableViewControllers....
Eric Schweichler
Okay, yes, thats what I thought, just making sure I had it right. I am going to try to rebuild it for a third time tonight. I've done a bunch of the tutorial apps that are in a couple of the books I have got, but this is the first one I am making from scratch, I'm sure im making a dumb error but I just cant figure out what it is. Thanks for your help.
Brodie
Eric - I was setting the class in the tab bar item but forgot to set the nib name in the tab view controller. Maybe it was the other way around but either way, i had not done both. Thanks for your help.
Brodie
Great, glad I could help!
Eric Schweichler
A: 

Try to add

@synthesize imageView;

into the @implementation of UseScrollViewViewController.

KennyTM
scrollView and imageView are already synthesized
Brodie