-(UINavigationController *) navigationControllerOfParentOrSelf //These 2 functions are short so I just go ahead
{
UIViewController * current=self;
while (current) {
UINavigationController * nav = current.navigationController;
if (nav) {
return nav;
}
current=current.parentViewController;
}
return nil;
}
-(UITabBarController *) tabBarControllerOfParentOrSelf
{
UIViewController * current=self;
while (current) {
UITabBarController * tc = current.tabBarController;
if (tc) {
return tc;
}
current=current.parentViewController;
}
return nil;
}
看起来像很多重复的代码。如何让这个UINavigationController寻求更优雅的代码?
基本上我只想知道一个UIViewController是否在UINavigationController中。事情是navigationController属性通常为零时的UIViewController是childViewController
你的循环是没有意义的。如果'navigationController'属性不为零,它将执行一次。如果它是零,它将永远运行。 –
固定。好的,那不是问题。 –