0

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];

}

Viraj
  • 1,880
  • 22
  • 31
  • 1
    Some code might help us understand you problem. Post the code where you create and push the view controller that should contain the scroll view and `viewDidLoad` in that view controller... – Michael Kessler Jul 18 '10 at 22:24
  • I have added the code. Its basically the same code as the pageControl sample given by apple http://developer.apple.com/iphone/library/samplecode/PageControl/Introduction/Intro.html . The modification I need is that instead of the scroll pages coming as soon as the application launches, i require it to be shown only after a click of a button. Thanks for your response. Greatly appreciate it. – Viraj Jul 19 '10 at 08:21
  • I have added the code. It is the same as the Pagecontrol sample given by apple http://developer.apple.com/iphone/library/samplecode/PageControl/Introduction/Intro.html . The only modification I need is that instead of the scroll pages coming as soon as the application launches, it should come after the click of a button or something. Thanks for your response, Greatly appreciate it. – Viraj Jul 19 '10 at 08:26

1 Answers1

0

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

TechZen
  • 64,370
  • 15
  • 118
  • 145
  • I have extended the class from a UIViewController and conformed to the UIScrollViewDelegate protocol. – Viraj Jul 18 '10 at 04:58
  • 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 Jul 18 '10 at 12:18
  • 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 Jul 19 '10 at 08:28