Why the UIScrollViewDelegate is not working?

回眸只為那壹抹淺笑 提交于 2019-12-11 18:29:36

问题


I have a viewController called "HaveScrollController", and this is something like this:

@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

and the .m is something like this:

@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

I make all the connection to the IB already. And I wanna to use this controller in my "TestAppController", which is something like this, it don't use IB, and generate the interface using code:

@interface TestAppController : UIViewController <UIScrollViewDelegate,UIActionSheetDelegate, UITextFieldDelegate> {
    HaveScrollController *scollViewController;
}

The .m is something like this in the loadView method:

scollViewController = [[HaveScrollController alloc] initWithNibName:@"HaveScrollView" bundle:nil];

[mainCanvas addSubview: buttomScollViewController.view];
self.view = mainCanvas;
[mainCanvas release];

When I try to scroll the view, but the "scroll detected" is not shown. What did I do wrong? thank you.


回答1:


Is scrollView scrolling at all? It looks like you forgot to set the contentSize:

scrollView.contentSize = CGSizeMake(320, 400);

Obviously, make sure the contentSize is larger than scrollView's frame so that the scrolling action kicks in.



来源:https://stackoverflow.com/questions/3518290/why-the-uiscrollviewdelegate-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!