将视图添加到 UIScrollView 末尾时出现问题

发布于 2024-10-30 19:30:38 字数 948 浏览 0 评论 0原文

我有一个包含一堆视图的 UIScrollView:

for(NSDictionary* deal in deals)
    {
        [items addObject:deal];

        DealViewController *dvc = [[DealViewController alloc] initWithNibName:@"DealViewController" bundle:nil];
        [dvc setNavigationController:[self navigationController]];
        UIView *dealView = [dvc view];
        [dealViewControllers addObject:dvc];

        //setup scrollView
        frame.origin.x = frame.size.width * i; 
        NSLog(@"Frame origin: %f", frame.origin.x);
        [dealView setFrame:frame];
        [scrollView addSubview:dealView];
        i++;
        [dvc displayDeal:deal];
    }

我想将一个视图添加到滚动视图的最末尾,如下所示:

SignUpViewController* signUpView = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil];
[scrollView insertSubview:signUpView.view atIndex:[items count]];

signUpView 出现在 UIScrollView 的开头。我怎样才能将它添加到最后?

I have a UIScrollView that contains a bunch of views:

for(NSDictionary* deal in deals)
    {
        [items addObject:deal];

        DealViewController *dvc = [[DealViewController alloc] initWithNibName:@"DealViewController" bundle:nil];
        [dvc setNavigationController:[self navigationController]];
        UIView *dealView = [dvc view];
        [dealViewControllers addObject:dvc];

        //setup scrollView
        frame.origin.x = frame.size.width * i; 
        NSLog(@"Frame origin: %f", frame.origin.x);
        [dealView setFrame:frame];
        [scrollView addSubview:dealView];
        i++;
        [dvc displayDeal:deal];
    }

I want to add a view to the very end of the scrollview as follows:

SignUpViewController* signUpView = [[SignUpViewController alloc] initWithNibName:@"SignUpViewController" bundle:nil];
[scrollView insertSubview:signUpView.view atIndex:[items count]];

The signUpView appears at the beginning of the UIScrollView. How can I add it to the end?

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

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

发布评论

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

评论(2

眼眸里的快感 2024-11-06 19:30:38
frame.origin.x = frame.size.width * i;
[signUpView setFrame:frame];

你没有告诉它在哪里画。

frame.origin.x = frame.size.width * i;
[signUpView setFrame:frame];

You didn't tell it where to draw.

怂人 2024-11-06 19:30:38

尝试使用

[scrollView insertSubview:signUpView.view atIndex:[items count] - 1];

如果您遇到问题请告诉我

Try With

[scrollView insertSubview:signUpView.view atIndex:[items count] - 1];

Let me know if you struggle with issue

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