views:

44

answers:

1

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  A: 

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.

dontGoPlastic
but I already make the scrollView in IB already...
Ted Wong
I'm pretty sure you still need to specify a contentSize, though. I don't see anywhere to specify that in IB so you might need to do it in code, in viewDidLoad.
dontGoPlastic