2010-07-14 77 views
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]; 
} 

預先感謝。我感謝你的幫助。

回答

0

這是piramidClicked:函數中的拼寫錯誤嗎?如果不是,這可能是這個問題:

-(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中做出正確的連接。希望有所幫助。

+0

完成! ..... initWithFrame是唯一的問題..... PrismView中的initWithFrame有錯誤,這就是爲什麼無法添加到viewcontroller的視圖。 RJ Regenold:實際上我沒有使用IB ...通過編程實現了一切。謝謝你的回覆。 – rohan 2010-07-14 05:29:33