0

I have UIScrollview that contains different UITableviews. You can scroll through these UITableviews using a UIPagecontrol.

This is how I add my UITableview to the UIScrollview

- (void)loadPage:(NSInteger)page {
    if (page < 0 || page >= self.pageStages.count) {
        // If it's outside the range of what we have to display, then do nothing
        return;
    }

    // Load an individual page, first seeing if we've already loaded it
    UIView *pageView = [self.pageViews objectAtIndex:page];
    if ((NSNull*)pageView == [NSNull null]) {
        CGRect frame = self.scrollView.bounds;
        //frame.size.width = 280.0f;
        frame.size.height = self.scrollView.bounds.size.height;

        float offset=20;
        frame.size.width = frame.size.width-(2*offset);
        frame.origin.x = (326 * page)+offset;
        frame.origin.y = 0;


        UITableView *tableStage = [[UITableView alloc]initWithFrame:frame];
        tableStage.backgroundColor = [UIColor colorWithRed:(250/255.0) green:(248/255.0) blue:(247/255.0) alpha:100];
        tableStage.contentMode = UIViewContentModeScaleAspectFit;
        tableStage.delegate = self;
        tableStage.dataSource = self;
        tableStage.tag = page;

        tableStage.contentMode = UIViewContentModeScaleAspectFit;
        [self.scrollView addSubview:tableStage];
        [self.pageViews replaceObjectAtIndex:page withObject:tableStage];
    }
}

Now I want that user can jump to a certain UITableview from another UIViewController. Therefore I have a variable pageNumber. When I set the pageNumber I call a method jumpToPage3 and I give the pageNumber with it. This is how the function looks like.

-(void)jumpToPage3:(NSNumber *)page{
    NSLog(@"jump to page 3");
    float offset=30;
    float height = self.scrollView.bounds.size.height;
    float width = 320 - (2*offset);
    int pagee = [page intValue] - 1;
    float x  = (320 * pagee) + offset;
    [self.scrollView scrollRectToVisible:CGRectMake(x, 0, width , height) animated:NO];
}

The problem is that it is not jumping to the correct page. It stays on the first page.

Can someone help me with this?

Steaphann
  • 2,797
  • 6
  • 50
  • 109

1 Answers1

0

When you add content to the scroll view you also have to tell increase the contentSize

Alex Terente
  • 12,006
  • 5
  • 51
  • 71
  • But my contentsize is oké I think ? Because when I just open the viewcontroller. I can swipe between the tableviews. the problem is only occuring when I jump to a page. – Steaphann Jun 21 '13 at 08:04
  • pass a hardcoded value to scrollRectToVisible: something like 800,0,1,1 and see what happens. Is your scroll view allocated and properly initialized when you call jumpToPage3? – Alex Terente Jun 21 '13 at 10:08