爲了支持縮放UIScrollView中的圖像,我想我必須將MyController與UIScrollViewDelegate一致,如下所示。但是,即使編譯器生成以下警告消息,它也能正常工作而不符合UIScrollViewDelegate。
警告:類「myController的」不執行「UIScrollViewDelegate」協議
是不是強制性的,以符合UIScrollViewDelegate在頭文件?
如果我忘記符合,是否有任何副作用?
爲什麼我可以支持縮放UIScrollView而不符合UIScrollViewDelegate?
//@interface MyController : UIViewController <UIScrollViewDelegate>
@interface MyController : UIViewController
{
UIScrollView *scrollView;
UIImageView *imageView;
}
@end
@implementation HelloController
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView;
}
- (void)loadView
{
UIImage *img = [UIImage imageNamed:@"foo.png"];
imageView = [[UIImageView alloc] initWithImage:img];
imageView.userInteractionEnabled = NO;
scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame]];
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:[imageView size]];
[scrollView setMaximumZoomScale:2.0f];
[scrollView setMinimumZoomScale:0.5f];
[scrollView setDelegate:self];
[scrollView addSubview:imageView];
self.view = scrollView;
[scrollView release];
}
@end
感謝您的回答。這對我來說很有意義。但是,如果我通過Interface Builder分配委託,則Interface Builder不會投訴。這是有趣的行爲。無論如何,再次感謝! – tomute 2010-02-06 17:17:15