模拟UINavigation推送问题?

时间:2011-05-12 22:00:57

标签: objective-c cocoa-touch xcode ios4 uinavigationcontroller

我想在一个XIB中切换两个视图,但我不想为此使用UINavigationController,因为它的效率非常低,因为只需要进行一次转换。这是我的代码:

// 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 个答案:

答案 0 :(得分:1)

该错误倾向于表明WebViewTwo不是UIView的子类,或者已经被释放,并且不再指向作为UIView的子类的对象。检查您定义WebViewTwo的头文件,并在将其添加为子视图之前添加NSLog(@"%@", webViewTwo);,以查看它的类型。

希望这有帮助。