添加从笔尖加载到框架中的子视图
我想通过单击按钮添加 nib 文件中的视图作为主视图的子视图,但它必须位于框架 (0,108,320,351) 中。我尝试过以下代码:
-(IBAction) displayJoinmeetup:(id)sender
{
[meetups removeFromSuperview]; //removing the older view
CGRect myFrame = CGRectMake(0, 108,320,351);
[joinmeetup initWithFrame:myFrame]; //joinmeetup declared in header file as IBoutlet UIView*joinmeetup
[self.view addSubview:joinmeetup];
}
这仅显示一个空白屏幕,否则如果我删除子视图显示覆盖整个屏幕的框架,我该如何正确执行此操作?
I want to add a view from a nib file as a subview of my main view at the click of a button, but it has to be in a frame (0,108,320,351). I've tried the following code:
-(IBAction) displayJoinmeetup:(id)sender
{
[meetups removeFromSuperview]; //removing the older view
CGRect myFrame = CGRectMake(0, 108,320,351);
[joinmeetup initWithFrame:myFrame]; //joinmeetup declared in header file as IBoutlet UIView*joinmeetup
[self.view addSubview:joinmeetup];
}
This displays only a blank screen, otherwise if I remove the frame the subview displays covering the whole screen, how can I properly do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建对象后,永远不应该对其调用 init...。如果您可以更改设置,则会有一个设置器。在本例中,它是 setFrame:
You should never call init... on an object after it has been created. If you can change a setting, there will be a setter for it. In this case, it is setFrame:
从 nib 加载的视图不会调用 initWithFrame。有关详细信息,请参阅 UIView 类参考。
您需要在界面生成器(检查器)中设置视图大小属性。
initWithFrame is not called for a view loaded from nib. See the UIView class ref for details.
You need to set the view size properties in interface builder (inspector).
您可以尝试如下:
You can try thi as follow:
我建议你尝试这个:
I suggest you try this: