-(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'屬性不爲零,它將執行一次。如果它是零,它將永遠運行。 –
固定。好的,那不是問題。 –