从 plist 加载滚动视图

发布于 2024-10-05 16:11:48 字数 1625 浏览 3 评论 0原文

事情是这样的:对于新闻应用程序,我在滚动视图中加载一个视图,以便在每个部分上进行水平分页,没问题,PageControl 演示帮助很大,但现在我需要在另一个滚动中加载视图以编程方式查看,这样我就可以显示每个部分的内容,问题是我需要 NIB 文件上已有的自定义设计视图,因此每个部分看起来都不同,所以我想使用 plist 在通用滚动视图上加载每个自定义视图。

这是我到目前为止得到的:

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

非常感谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倥絔 2024-10-12 16:11:48

如果您的所有视图都有自己的 nib,这可能会起作用:

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

因此您可以将每个 nib 的名称保存在 plist 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文