- (void)pushViewDetailViewCtrl:(UIViewController *)deViewCtrl andView:(UIView *)view{ UIViewController *vc = (id)view.nextResponder; if ([vc isKindOfClass:[UIViewController class]]) { [vc.navigationController pushViewController:deViewCtrl animated:YES]; }else{ [self pushViewDetailViewCtrl:deViewCtrl andView:view.superview]; } }
注意:優化
普通遞歸:可能棧溢出crashcode
尾隨遞歸:把累加結果也傳到下一次調用(有些編譯器能夠對尾隨遞歸進行優化,不過Swift不行,因此仍然可能出現棧溢出crash)遞歸