xcode 将类/对象添加到子视图
希望你能帮忙。我基本上需要将一个对象添加到 UIView 内的 UIView 中。
在界面生成器中,我有我的视图,在其中我有另一个视图,里面有图像(地图)(所有这些都是用界面生成器完成的)。我使用的第二个视图是一个名为“MainGameMapViewController”的类(原因是第一个视图是静态的/包含文本/分数等,而里面的视图是游戏,并且整个视图可以使用“MainGameMapViewController”中的代码进行拖动”)。
我需要将对象添加到“MainGameMapViewController”UIView。
我添加了一个名为“CharMain”的类,并在 MainViewController 中使用了此代码:
-(void) viewWillAppear:(BOOL)animated {
CharMain* charMain = [[CharMain alloc] initWithFrame:CGRectMake(40, 280, 0, 0)];
[self.view addSubview:charMain];
}
CharMain 包含绘制矩形并添加图像的代码,这工作正常,但需要将其添加到第二个查看“MainGameMapViewController”。
我尝试在 MainGameMapViewController 文件中添加代码,它显示“错误:请求成员‘视图’不是结构或联合”,我尝试过 [自我添加子视图:charMain];
这没有错误,但图像没有出现,如何使其出现在第二个 UIView 中?谢谢!
Hope you can help. I basically need to add an object to a UIView that is within a UIView.
In interface builder I have my View, and inside that I have another View with an image (map) inside (all done with Interface Builder). The second view I am using a class called "MainGameMapViewController" (reason being is that the first view is static/contains text/scores etc. and the view inside that is the game, and this whole view is draggable with the code in "MainGameMapViewController").
I need to add objects to "MainGameMapViewController" UIView.
I have added a class called "CharMain" and used this code inside the MainViewController:
-(void) viewWillAppear:(BOOL)animated {
CharMain* charMain = [[CharMain alloc] initWithFrame:CGRectMake(40, 280, 0, 0)];
[self.view addSubview:charMain];
}
CharMain contains the code that draws a rect and adds an image, this works fine, BUT it needs to be added to the second view "MainGameMapViewController".
I have tried adding the code inside the MainGameMapViewController file, and it says "error: request for member 'view' in something not a structure or union", I have tried
[self addSubview:charMain];
This comes up with no errors, but the image doesnt appear, how do I make this appear within the second UIView? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)