将 UIImageView 添加到 UIScrollView 会引发异常 cocoa touch for iPad
我是 OBJ-C 的菜鸟:)
我正在尝试将 UIImageView 添加到 UIScrollView 以在我的 iPhone 应用程序中显示大图像。
我完全按照这里的教程进行操作:
http ://howtomakeiphoneapps.com/2009/12/how-to-use-uiscrollview-in-your-iphone-app/
唯一的区别是,在我的应用程序中,视图位于单独的选项卡中,我正在使用不同的图像。
这是我的代码:
- (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;
}
然后,
@interface UseScrollViewViewController : UIViewController<UIScrollViewDelegate>{
IBOutlet UIScrollView *scrollView;
UIImageView *imageView;
}
@property (nonatomic, retain) UIScrollView *scrollView;
@property (nonatomic, retain) UIImageView *imageView;
@end
我在 Interface Builder 中创建一个 UIScrollView 并将其链接到scrollView 出口。那就是我遇到问题的时候。当我运行该程序时,它立即崩溃。 如果我在没有将滚动视图链接到插座的情况下运行它,它将运行(尽管带有 blnk 屏幕)。
以下是我在控制台中收到的错误:
2010-03-27 20:18:13.467 UseScrollViewViewController[7421:207]
*** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[
” setValue:forUndefinedKey:]: 这个类不符合键值scrollView的键值编码。'
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.'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加
到
UseScrollViewViewController
的@implementation中。Try to add
into the @implementation of
UseScrollViewViewController
.由于没有公认的答案可以解决问题,我想我发布的答案解决了我的类似问题。
当使用标签栏时,您还应该检查IB中标签栏控制器的属性。您的视图控制器的类型(位于选项卡栏控制器项下,我猜是在 MainWindow.xib 中)很可能是 UIViewController。将其更改为您的特定控制器。
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.
首先,强制性的“iPad SDK 仍处于 NDA 之下,因此您不应该在此处发布此问题,我们无法帮助您”。
现在,如果这是 iPhone 应用程序,我会说检查界面生成器:单击“文件所有者”,然后在检查器中,确保该类设置为您用于加载笔尖的类。
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.