-(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;
}
そこには多くの繰り返されるコードのように見えます。
基本的に、UIViewController が UINavigationController 内にあるかどうかを知りたいだけです。UIViewController が childViewController の場合、navigationController プロパティは多くの場合 nil です。