2011-05-12 71 views
1

我在一個希望切換的XIB中有兩個視圖,但我不想爲此使用UINavigationController,因爲它的效率非常低,因爲只有一個需要發生的轉換。這裏是我的代碼:模擬UINavigation推送問題?

// get the view that's currently showing 
UIView *currentView = self.view; 
// get the the underlying UIWindow, or the view containing the current view view 
UIView *theWindow = [currentView superview]; 

// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromLeft]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[theWindow addSubview:webViewTwo]; 

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"]; 

.H

@class WebViewTwo; 
@interface SecondViewController : UIViewController { 
IBOutlet WebViewTwo *webViewTwo; 
} 

現在,它的一個錯誤

2011-05-12 16:59:59.528 TableView[36627:207] -[WebViewTwo superview]: unrecognized selector sent to instance 0x603b660 
2011-05-12 16:59:59.531 TableView[36627:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebViewTwo superview]: unrecognized selector sent to instance 0x603b660' 

請幫崩潰了!謝謝。

回答

1

錯誤往往會建議無論WebViewTwo不是UIView一個子類,或者已經perviously被釋放,不再指向的對象是UIView子類。檢查您定義WebViewTwo的頭文件,並在將其添加爲子視圖之前添加NSLog(@"%@", webViewTwo);,以查看它是什麼類型。

希望這會有所幫助。

+0

這不是零,並沒有被釋放......明白了:''。我有這在我的WebViewTwo.h'@interface WebViewTwo:UIViewController {'...我如何改變它並將其子類化爲一個UIView? – iosfreak 2011-05-27 00:36:45

+0

只是在開玩笑。如果其他人有這個問題,只需創建一個UIView的IBOutlet並將其與您的視圖連接並顯示它! – iosfreak 2011-05-27 00:42:29