I'm just learning how to scroll with UIScroll. Most posts I've read about it involve people who already have scrolling implemented, and just need tweaking to get over a hump. I'm starting from scratch. It's not clear to me from the Apple docs where I put the scrolling code - on the same .m viewcontroller file that is to scroll? I am not using IB, for I am starting from Apple's UICatalog, ("SegmentViewController"), which is hard-coded. This is the code I have:
First up is the AppDelegate, then the MainViewController (a TableView), then a UIView (SegmentViewController, which appears after tapping a cell in the MainViewController).
It seems to me that the myView should be initWithName, and put the SegmentViewController there, but isn't the code supposed to work with ALL cells on the MainViewController? Or do we add the scroll code to each UIView we want scrolled? I know TableViews already implement scrolling by default.
I'm not sure where to put it or how to link it to the views to be scrolled. Can you give me some pointers based on the info above?
Thanks!
Steve
Code:
-(void)loadView {
CGRect appFrame =[[UIScreen mainScreen] applicationFrame];
myView = [[UIView alloc] initWithFrame:appFrame];
self.view = myView;
[myView release];
myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
myScrollView setContentSize:CGSizeMake(320, 1000)];
myScrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
myScrollView.contentSize = myView.frame.size;
myScrollView.clipsToBounds = YES;
myScrollView.scrollEnabled = YES;
myScrollView.bounces = YES;
myScrollView.scrollsToTop = YES;
myScrollView.pagingEnabled = YES;
myScrollView.delaysContentTouches = NO;
myScrollView.showsVerticalScrollIndicator = YES;
myScrollView.showsHorizontalScrollIndicator = NO;
myScrollView.delegate = self;
[myScrollView addSubView:myView];
[myScrollView release];
}
First up is the AppDelegate, then the MainViewController (a TableView), then a UIView (SegmentViewController, which appears after tapping a cell in the MainViewController).
It seems to me that the myView should be initWithName, and put the SegmentViewController there, but isn't the code supposed to work with ALL cells on the MainViewController? Or do we add the scroll code to each UIView we want scrolled? I know TableViews already implement scrolling by default.
I'm not sure where to put it or how to link it to the views to be scrolled. Can you give me some pointers based on the info above?
Thanks!
Steve