我有一个名为“HaveScrollController”的viewController,这是这样的:
@interface HaveScrollController : UIViewController <UIScrollViewDelegate>{
IBOutlet UIScrollView *scrollView;
IBOutlet UIView *firstView;
IBOutlet UIView *secondView;
IBOutlet UIView *thridView;
IBOutlet UIView *fourthView;
}
@property (retain, nonatomic) UIScrollView *scrollView;
@property (retain, nonatomic) UIView *firstView;
@property (retain, nonatomic) UIView *secondView;
@property (retain, nonatomic) UIView *thridView;
@property (retain, nonatomic) UIView *fourthView;
@end
和.m是这样的:
@synthesize scrollView,firstView,secondView,thridView,fourthView;
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:scrollView];
scrollView.delegate = self;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"scroll detected");
}
@end
我已经完成了与IB的所有连接。我想在我的“TestAppController”中使用这个控制器,就像这样,它不使用IB,并使用代码生成接口:
@interface TestAppController : UIViewController <UIScrollViewDelegate,UIActionSheetDelegate, UITextFieldDelegate> {
HaveScrollController *scollViewController;
}
.m在loadView方法中是这样的:
scollViewController = [[HaveScrollController alloc] initWithNibName:@"HaveScrollView" bundle:nil];
[mainCanvas addSubview: buttomScollViewController.view];
self.view = mainCanvas;
[mainCanvas release];
当我尝试滚动视图时,但未显示“检测到滚动”。我做错了什么?谢谢。
答案 0 :(得分:2)
scrollView
是否完全滚动?您似乎忘了设置contentSize
:
scrollView.contentSize = CGSizeMake(320, 400);
显然,请确保contentSize
大于scrollView's
框架,以便滚动操作启动。