开发者

self.view addSubview:view problem..!

开发者 https://www.devze.com 2023-01-06 21:25 出处:网络
newbie in ipad apps here n stucked on a very strange condition. I have one view based application. In view of Viewcontroller I have added two buttons to draw to shapes. One is cube and one is pirami

newbie in ipad apps here n stucked on a very strange condition.

I have one view based application. In view of Viewcontroller I have added two buttons to draw to shapes. One is cube and one is piramid. Shapes are drawn with openGL code. Both shapes have different view classes.

Now on clicking on the buttons of cube and pyramid respectively, shapes should be drawn into the view of viewController. I am successfully drawing cube shape but cannot draw pyramid shape..!!!

after trying different methods i came to conclusion that "self.view addSubView:tempView" is the problem. This code works fine with cube button , but not with pyramid. Cant fine the exact problem.

here is sample of code

buttons :

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];

methods sample code:

-(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];
}

Thanks in advance开发者_Go百科. I appreciate your help guys.


Is that a typo in your piramidClicked: function? If not, that could be the issue:

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

If it is a typo, I'd check to make sure you made your connections correctly in Interface Builder. Hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号