0
新手在ipad应用程序这里n被卡住在一个非常奇怪的条件。self.view addSubview:查看问题..!
我有一个基于视图的应用程序。 鉴于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];
}
预先感谢。我感谢你的帮助。
完成! ..... initWithFrame是唯一的问题..... PrismView中的initWithFrame有错误,这就是为什么无法添加到viewcontroller的视图。 RJ Regenold:实际上我没有使用IB ...通过编程实现了一切。谢谢你的回复。 – rohan 2010-07-14 05:29:33