2011-05-12 53 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