将xib放入UIView控件iphone中
我知道如何在“主”视图控制器中放置一个 nib 文件:
当我执行此方法时将显示新的 nib 文件。
是否可以将该 nib 文件放入 UIView 控制器中?
我想将该 nib 文件放置在该视图控制器中而不是主视图中。我怎么能这么做呢?
编辑:
我尝试做你提到的保罗,我不知道我做错了什么。无论如何,这就是我所做的:
我使用您提到的属性和方法创建了另一个视图控制器。
我将我的 IBoutlet UIView *exampleView
连接到基本视图:
然后从这里我迷失了,我不知道在哪里放置其他方法。我想将该 exampleView 放入:
该视图。
我尝试将它们放在 pgBackground.m 中,但它不起作用。我想将它们放置在 IBaction 中,以便我可以通过带有按钮的内部事件触摸来加载它。
I know how to place a nib file in the "main" view controller:
when I execute this method a new nib file will be displayed.
Is it possible to place that nib file in a UIView controller instead?
I want to place that nib file in that view controller instead of in the main view. How could I do that?
Edit:
I tried doing what you mention Paul I don't know what am I doing wrong. Anyways here is what I did:
I created another view controller with the properties an methods you mentioned.
I hooked up my IBoutlet UIView *exampleView
to the base view:
then from here I am lost I don't know where to place the other methods. I would like to place that exampleView into:
that view.
I have tried placing them in pgBackground.m but it does not work. I want to place them inside an IBaction so that I can load that with a touch up inside event with a button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我设法将 nib 文件放置在 uiview 控件中,但我遇到的问题是,如果设备旋转,子视图将不会旋转。我目前正在研究解决方案,但到目前为止 这是一个问题,可以向您展示如何将另一个 nib 文件中的视图添加到 uiview 控件。
I managed to place a nib file in a uiview control but I have the problem that the subview will not rotate if the device does. I am currently working on a solution to this but so far here is a question that can show you how to add the view from another nib file to a uiview control.
如果我遵循,我认为您将需要:
创建一个具有关联 xib 的 UIView 子类
设置一个属性来包含视图层次结构(您想要在界面构建器中连接的所有内容)
在
ExampleView.m
您需要添加:您使用 nib 唤醒,以便您可以在 Interface Builder 中使用此子类。如果您还想在代码中实例化它,则需要在 init 方法中连接 xib。在这种情况下,我可能会像这样提取笔尖加载:
在ExampleView.xib文件中,确保将您的
IBOutlet UIView *exampleView
连接到基本视图。现在,在您想要使用自定义视图的任何 xib 文件中,只需将其拖到窗口中并将类更改为您的子类即可。这就是我的工作方式,我期待有人提出改进建议。
If I follow I think you will need to:
Create a
UIView
sub class with associated xibSet up a property to contain the View hierarchy (everything you want to be hooked up in Interface builder)
In the
ExampleView.m
you need to add:You use awake from nib so you can use this sub class in Interface Builder. If you also want to instantiate it in code you need to hook up the xib in the init method. In this case I would probably extract the nib loading like so:
In the ExampleView.xib file make sure to hook up your
IBOutlet UIView *exampleView
to the base view.Now in any xib file where you want to use your custom view simply drag it into your window and change the class to your subclass. This is how I got it working I look forward to some people suggesting improvements.
你能告诉我你想做什么吗?如果你想改变方向,那么首先你在应用程序委托文件中声明一个 bool en 类型变量,然后在应用程序 delegate.m 文件中定义,如果方向改变,然后检测并使布尔类型变量对于横向为 true,对于纵向为 false。此过程用于接下来的所有视图。并且您希望在主视图控制器中执行 nib,那么您有两种方法,一种是动态的,另一种是通过界面生成器执行的。在界面生成器中 u 选择导航控制器并放入主窗口文件中。之后,您可以通过按 cmd+4 更改导航控制器的视图,然后选择要首先显示的视图。
can u tell me what u want to do? if u want to change orientation then first u declare a bool en type variable in app delegate file then define in app delegate.m file if orientation change then detect and make Boolean type variable true for landscape and false for portrait. this process use for next all views. and u want u execute nib in main view controller then u have two ways one is dynamically and other by interface builder. in interface builder u Select navigation controller and drop in main window file . after that u change the view of navigation controller's view by press cmd+4 and select view which u want to display first.
-(IBAction)btnSubmit_click{
}
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) 接口方向
{
}
-(IBAction)btnSubmit_click{
}
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
}