开发者

Why the UIScrollViewDelegate is not working?

开发者 https://www.devze.com 2023-01-11 23:49 出处:网络
I have a viewController called \"HaveScrollController\", and this is something like this: @interface HaveScrollController : UIViewController <UIScrollViewDelegate>{

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 (r开发者_运维技巧etain, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消