开发者

adding UIImageView to UIScrollView throws exception cocoa touch for iPad

开发者 https://www.devze.com 2022-12-25 01:43 出处:网络
I am a noobat OBJ-C :) I am trying to add a UIImageView to a UIScrollView to display a large image in my iPhone app.

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 outl开发者_高级运维et. 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.'


Try to add

@synthesize imageView;

into the @implementation of UseScrollViewViewController.


As there was no accepted answer solving the problem I figured I post my answer which solved my similar problem.

As tab bar is being used, you should also check the Tab Bar Controller's attributes in IB. Most probably the type for your view controller (which is under Tab Bar Controller item, which is I guess in MainWindow.xib) is UIViewController. Change it to your specific controller.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消