views:

63

answers:

1

Hello All,

I am looking for some help for a program I am developing. Basically, it contains two views. The first view has a button and a action related to it leads me to my next view where there is a scroll view for three pages ( as in the PageControl sample given by apple.) I am using navigation controller to push the view from the first view to the second view. But on pushing I am not able to scroll the page or using page control or anything. It just comes a normal view. The code is same as pageControl code and it works fine as a separate module. But when I want to integrate this pageControl code with a first view and a click button it doesn't work. Please help.

//this function is an action set against a button in the rootviewcontroller.

-(IBAction) viewScrollPages:(id)sender{
UIViewController *controller = [[MyViewController alloc] initWithPageNumber:0];
[self.navigationController pushViewController:controller animated:NO];
[controller release];

}

- (id)initWithPageNumber:(int)page {
if (self = [super initWithNibName:@"MyViewController" bundle:nil]) {
    pageNumber = page;
}   
return self;

}

- (void)viewDidLoad {   
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
    [controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
[super viewDidLoad];

}

A: 

It sounds like your pushing a normal view that is a subview of the scrollview instead of pushing the scrollview itself.

TechZen
I have extended the class from a UIViewController and conformed to the UIScrollViewDelegate protocol.
Viraj
That is your controller for the scrollview. I think you've got the wrong view set for scrollview's controller's view such that when you push the controller, it puts up one of the subviews of the scrollview instead of the scrollview itself.
TechZen
Yes, i guess that is the problem. How would I be able to push the scroll view rather than the sub view of the scroll view ? I have attached the code for reference. Thanks for the help.
Viraj