Question

here is the deal: For a news app, I'm loading a view inside a Scroll View for horizontal paging on each section, no problem with that, the PageControl demo helped a lot, but now I need to load a View inside another Scroll View programmatically so I can show the content of each section, the deal is that I need custom designed views already on a NIB file so each section looks different, so I would like to use a plist to load each custom view on the generic Scroll View.

Here is what I got until now:

- (void)loadScrollViewWithPage:(int)page{
    if (page < 0)
        return;
    if (page >= kNumberOfPages)
        return;

    // replace the placeholder if necessary
    Seccion *controller = [viewControllers objectAtIndex:page];
    if ((NSNull *)controller == [NSNull null])
    {
        controller = [[Seccion alloc] initWithPageNumber:page];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        [controller release];
    }

    // add the controller's view to the scroll view
    if (controller.view.superview == nil)
    {
        NSDictionary *numberItem = [self.contentList objectAtIndex:page];
        //UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1.jpg" ofType:nil]];

        controller.sectionTitle.text = [numberItem valueForKey:Nombre];
        controller.sectionView.text = [numberItem objectForKey:Vista];
        controller.sectionId.text =    [numberItem valueForKey:Id];



        //Here is supposed to have the code to load the view inside the scroll view  I tried using: [controller.sectionScrollView addSubview:controller.sectionView.text];

        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollView addSubview:controller.view];        
    }
}

Thanks a lot in advance

Was it helpful?

Solution

If all your views have it own nib, this might work:

UIView *view = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] objectAtIndex:0];

so you can save the name of each nib in a plist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top