Ipad self.view addSubview:视图问题。。!

Ipad self.view addSubview:视图问题。。!,ipad,Ipad,ipad应用程序中的新手在一个非常奇怪的情况下结巴 我有一个基于视图的应用程序。 在Viewcontroller视图中,我添加了两个按钮来绘制形状。一个是立方体,一个是皮拉米。形状是用openGL代码绘制的。这两种形状具有不同的视图类 现在,分别单击立方体和棱锥体的按钮,形状应绘制到viewController的视图中。我正在成功绘制立方体形状,但无法绘制金字塔形状 在尝试了不同的方法之后,我得出结论,“self.view addSubView:tempView”就是问题所在。此代码适用于立方体

ipad应用程序中的新手在一个非常奇怪的情况下结巴

我有一个基于视图的应用程序。 在Viewcontroller视图中,我添加了两个按钮来绘制形状。一个是立方体,一个是皮拉米。形状是用openGL代码绘制的。这两种形状具有不同的视图类

现在,分别单击立方体和棱锥体的按钮,形状应绘制到viewController的视图中。我正在成功绘制立方体形状,但无法绘制金字塔形状

在尝试了不同的方法之后,我得出结论,“self.view addSubView:tempView”就是问题所在。此代码适用于立方体按钮,但不适用于金字塔。我不能解决确切的问题

下面是代码示例

按钮:

cubeButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(600, -5, 50, 50)];
[cubeButton addTarget:self action:@selector(cubeClicked:) forControlEvents:UIControlEventTouchUpInside];
[cubeButton setBackgroundImage:[UIImage imageNamed:@"square_3D.png"] forState:UIControlStateNormal];

pyramidButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(700, -5, 50, 50)];
[pyramidButton addTarget:self action:@selector(piramidClicked:) forControlEvents:UIControlEventTouchUpInside];
[pyramidButton setBackgroundImage:[UIImage imageNamed:@"triangle_3D.png"] forState:UIControlStateNormal];
方法示例代码:

-(IBAction) cubeClicked:(id)sender {
    UIView *cubeView = [[CubeView alloc] initWithFrame:CGRectMake(250, 60, 500, 600)];
    [self.view addSubview:cubeView];
}

-(IBAction) piramidClicked:(id)sender {
    UIView *pyramidView = [[pyramidView alloc] initWithFrame:CGRectMake(250, 60, 500, 600)];
    [self.view pyramidView];
}

提前谢谢。感谢你们的帮助。

这是您的
函数中的输入错误吗?如果不是,这可能是一个问题:

-(IBAction)piramidClicked:(id)sender {
    UIView *pyramidView = [[PyramidView alloc] initWithFrame...];
    // this line probably causes a compiler warning ...
    // [self.view pyramidView];
    [self.view addSubview:pyramidView];
}

如果是输入错误,我会检查以确保您在Interface Builder中正确连接。希望能有所帮助。

完成。。。。。initWithFrame是唯一的问题。。。。。PrismView中的initWithFrame出现错误,因此无法添加到viewcontroller的视图中。RJ Regenold:事实上我没有使用IB…一切都是通过编程实现的。谢谢你的回复。