[英] Monotouch: UINavigationController, override initWithRootViewController
问题描述
如何覆盖UINavigationController的构造函数传递一个rootViewController?
How is it possible to override the constructor for UINavigationController for passing in a rootViewController?
我会在Objective-C中有一个类似下面的方法:
I would have a method like the following in Objective-C:
-(id)initWithRootViewController:(UIViewController*)rootViewController
{
UIViewController *fakeController = [[[UIViewController alloc] init] autorelease];
if (self = [super initWithRootViewController:fakeController]) {
self.fakeRootViewController = fakeController;
rootViewController.navigationItem.hidesBackButton = YES;
[self pushViewController:rootViewController animated:NO];
}
return self;
}
提前感谢。尊敬的。
PS这段代码取自更改根视图控制器
:
感谢您的回复。我对以前的代码段感兴趣,因为它非常有趣。
Thank you for your replies. I was interested in the previous snippet of code because it's particular interesting.
@Geoff Norton:也许我永远不会使用你的解决方案,
@Geoff Norton: Maybe I'll never use your solution but I find it amazing anyway...
我的尝试是创建一个UINavigationViewController作为模板。特别是,UINavigationController最初有一个loginView(它可能是一种rootviewcontroller)。然后登录时,我可以有两种类型的视图:主视图和辅助视图。前者在登录视图的同一级别(他们可以是一种rootviewcontrollers)。后者被推到第一个之上。您可以浏览正常的UInavigationController堆栈或通过工具栏。工具栏只加载主视图。
My attempt is to create a sort of UINavigationViewController that acts as a template. In particular, the UINavigationController initially has a loginView (it could be a sort of rootviewcontroller). Then when logging in, I could have two type of views: main and secondary views. The former are at the same level of the login view (they could be a sort of rootviewcontrollers). The latter are pushed above the first ones. You can navigate through the normal UInavigationController stack or by means of a toolbar. The toolbar loads only main view.
是否可以使用UINavigationController执行此操作?
Is it possible to do this with a UINavigationController?
。
推荐答案
它可能,但你不应该这样做。根据苹果UINavigationController是不是为子类化。如果你坚持这样做:
Its possible but you shouldn't do it. According to Apple the UINavigationController is "not designed for subclassing". If you insist on doing this:
public YourNavController : UINavigationController {
[Export ("initWithRootViewController:")]
public YourNavController (UIViewController vc) {
UIViewController fc = new UIViewController ();
Handle = Messaging.intptr_objc_msgSend_intptr (this.Handle, Selector.GetHandle ("initWithRootViewController:"), fc.Handle);
FakeRootViewController = fc;
vc.NavigationItem.HidesBackButton = true;
PushViewController (vc, false);
}
}
接近的东西应该可以工作。
Something close to that should work.
这篇关于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!