2011-11-28 76 views
-1
XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate]; 
CSelectorViewController *cPrice=[[CSelectorViewController alloc] initWithNibName:@"CSelectorViewController" bundle:nil]; 
[cPrice.view setFrame:CGRectMake(0, 20, 320, 480)]; 
[appdelegate.window addSubview:cPrice.view]; 

[self applyAnimation]; 
[cPrice release]; 

我加入這樣的圖,不使用navigationcontroller,因爲我必須切換兩個視圖當我給予[cPrice釋放]上下also.but;該應用程序崩潰。但是當我沒有在代碼中給它...靜態分析器顯示警告什麼是正確的方式來做到這一點?切換兩個視圖導致崩潰

-(void)applyAnimation 
{ 
    CATransition *animation = [CATransition animation]; 
    [animation setDuration:0.5]; 
    [animation setType:kCATransitionPush]; 
    [animation setSubtype:kCATransitionFromRight]; 
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
    XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate]; 
    [[appdelegate.window layer] addAnimation:animation forKey:@"slideLeft"]; 
} 
+0

與什麼錯誤崩潰?控制檯中有什麼? –

+0

發送到釋放實例的消息...我知道它由於內存問題,只是想知道什麼是正確的方式來做...沒有內存泄漏 – sujith1406

回答

0

您要添加cPrice的view到窗口作爲一個子視圖(這將隱含保留的觀點),但是你什麼都不做保存cPrice本身。你應該把它作爲一個保留的財產或一些這樣的。