为什么UIScrollViewDelegate不起作用?

时间:2010-08-19 02:32:23

标签: iphone objective-c iphone-sdk-3.0

我有一个名为“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];

当我尝试滚动视图时,但未显示“检测到滚动”。我做错了什么?谢谢。

1 个答案:

答案 0 :(得分:2)

scrollView是否完全滚动?您似乎忘了设置contentSize

scrollView.contentSize = CGSizeMake(320, 400);

显然,请确保contentSize大于scrollView's框架,以便滚动操作启动。