模拟UINavigation推送问题?
我在一个 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'
请帮忙!谢谢。
I have two views in one XIB I want to switch, but I don't want to use a UINavigationController for this, because it's horribly inefficient because there is only one transition that will need to occur. Here's my code:
// 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;
}
Now it's crashing with an error
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'
Please help! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误往往表明
WebViewTwo
不是UIView
的子类,或者之前已发布并且不再指向UIView< 子类的对象/代码>。检查定义
WebViewTwo
的头文件,也许在将其添加为子视图之前添加NSLog(@"%@", webViewTwo);
以查看它是什么类型。希望这有帮助。
The error would tend suggest that either
WebViewTwo
is not a subclass ofUIView
or has perviously been released and is no longer pointing to an object that is subclass ofUIView
. Check the header file where you defineWebViewTwo
and perhaps addNSLog(@"%@", webViewTwo);
before you add it as a subview just to see what type it is.Hope this helps.