如何在 uiview 控制器上导入视图控制器?

发布于 2024-12-25 21:43:38 字数 1073 浏览 3 评论 0原文

可能这对某人来说很愚蠢,但我需要这个问题的解决方案。我想在另一个视图控制器上添加一个视图控制器。如果我解释一下,

  1. 我的主视图控制器包含一个 uitableview。
  2. 我的另一个视图控制器包含按钮的滚动视图。

现在我想将滚动视图控制器设置在主视图控制器的顶部[它采用 uitableview]。这意味着[mainview addsubview:scrollview控制器]

注意:我的滚动视图是一个视图控制器,它正在获取一些按钮的滚动视图。

如果有人给出有关这些问题的任何示例或源代码或教程链接,那么它对我很有帮助。

提前致谢。

编辑:

到目前为止我已经完成了...

在.h文件中

#import "scrollViewButtons.h"
scrollViewButtons *scrollButtonView;
@property (nonatomic,retain) scrollViewButtons *scrollButtonView;

在.m文件中

@synthesize scrollButtonView;

viewDidLoad

scrollButtonView = [[scrollViewButtons alloc] initWithNibName:@"scrollViewButtons" bundle:nil];
CGRect frame = CGRectMake(0, 0, 320, 43);
scrollButtonView.view.frame = frame;
scrollButtonView.view.userInteractionEnabled =YES;
[self.view addSubview:scrollButtonView.view];   

现在我可以在我的主视图中看到scrollButtonView,但我找不到任何用户交互。我无法滚动按钮的滚动视图。有人能告诉我为什么我无法与该滚动按钮视图交互吗?

May be it will a stupid for someone but i need the solution of this problem.I want to add a view controller on another view controller.If I explain it then,

  1. My main view controller is containing a uitableview.
  2. My another view controller containing a scrollview of buttons.

Now I want to set my scrollview controller at the top of the my main view controller [which is taking uitableview]. Thats mean [mainview addsubview:scrollview controller]

NOTE THAT: My scrollview is a view controller which is taking scrollview of some buttons.

If somebody give any example or source code or link of tutorial on these problem then it will very much helpful for me.

Thanks In advance.

EDIT:

Till now i have done...

In .h file

#import "scrollViewButtons.h"
scrollViewButtons *scrollButtonView;
@property (nonatomic,retain) scrollViewButtons *scrollButtonView;

In .m file

@synthesize scrollButtonView;

In viewDidLoad

scrollButtonView = [[scrollViewButtons alloc] initWithNibName:@"scrollViewButtons" bundle:nil];
CGRect frame = CGRectMake(0, 0, 320, 43);
scrollButtonView.view.frame = frame;
scrollButtonView.view.userInteractionEnabled =YES;
[self.view addSubview:scrollButtonView.view];   

Now i can see the scrollButtonView in my main view but i can not find any user interaction.I can not scroll the scrollview of buttons.Can anybody tell me why i am not being able to interact with that scrollButtonView?

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

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

发布评论

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

评论(1

何止钟意 2025-01-01 21:43:38

您将视图与视图控制器混淆了。显然,您有两个具有单独视图控制器的视图,并且您希望这些视图出现在另一个视图中。这很容易做到。

如果您有一个视图控制器(例如firstVC),那么您可以通过将该视图添加到另一个视图(例如bigView)来添加它控制的视图。如果

[bigView addSubview:firstVC.view];

您有第二个视图控制器,例如 secondaryVC,那么您可以通过将该视图添加到另一个视图 bigView 来添加它控制的视图。 现在你只需要使用

[bigView addSubview:secondVC.view];

视图控制器来管理视图bigView。

您可以根据您的理解程度以及您想要的复杂程度或简化程度来改变这一点。大多数视图控制器管理多个 UIView——如标签、按钮、文本字段和其他视图。但是,您可以在第一个视图控制器 (firstVC) 内实例化第二个视图控制器 (secondVC),然后将 secondaryVC 的视图添加到firstVC 的视图中,如下所示:

[firstVC.view addSubView:secondVC.view];

我希望有所帮助。

You are confusing views with view controllers. Apparently you have two views that have separate view controllers and you and you want these views to appear inside another view. That's very easy to do.

If you have a view controller, such as firstVC, then you can add the view that it controls by adding that view to another view, such as bigView. just use

[bigView addSubview:firstVC.view];

If you have a second view controller, such as secondVC, then you can add the view that it controls by adding that view to the another view, bigView. just use

[bigView addSubview:secondVC.view];

Now you only need to manage the view bigView with a view controller.

You can vary this, depending on your level of understanding and the level of complexity or simplification you want to have. Most view controllers managed several UIViews -- like labels, buttons, text fields, and other views. However, you may instantiate a second view controller (secondVC) inside the first view controller (firstVC) and then add the view of secondVC into the view of firstVC, like this:

[firstVC.view addSubView:secondVC.view];

I hope that helps.

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