songxing10000 commented on issue #1721: weex navigator如何清除导航堆栈
URL: https://github.com/apache/incubator-weex/issues/1721#issuecomment-441211235
 
 
   @anrananran 
   大约是这个样子
   ```objc
   /// 回到某个页面,原生页面,或者weex页面
   - (void)backToVC:(NSString *)vcClassName weexUrlString:(NSString 
*)weexUrlString {
       if ([vcClassName isEqualToString:@"KYWeexVC"]) {
           [self backToWeexVC:weexUrlString];
       }else{
           UINavigationController *nav = [weexInstance.viewController 
navigationController];
           NSArray <UIViewController *> *vcs = nav.childViewControllers;
           [vcs enumerateObjectsUsingBlock:^(UIViewController * _Nonnull vc, 
NSUInteger idx, BOOL * _Nonnull stop) {
               if ([vc isKindOfClass: NSClassFromString(vcClassName)]) {
                   [nav popToViewController:vc animated:NO];
               }
           }];
       }
   }
   /// 回到weex页面
   -(void)backToWeexVC:(NSString*)weexUrlString {
       NSString *pageid = [weexUrlString 
componentsSeparatedByString:@"?"].firstObject;
       KYWeexVC *popVC = nil;
       KYWeexVC *vc =  (KYWeexVC *)weexInstance.viewController;
       for (KYWeexVC *v in vc.navigationController.viewControllers) {
           if ([v isKindOfClass:[KYWeexVC class]]) {
               
               if([pageid isEqualToString:v.pageid]) {
                   
                   popVC = v;
               }
           }
       }
       /// 切换时,加上过度动画
       [[AppDelegate sharedInstance] addAnimationWhenSetWindowRootVC];
       
       if (popVC != nil) {
           [vc.navigationController popToViewController:popVC animated:NO];
       } else {
           /// 堆栈里没找到对应weex,强制设置
           KYWeexVC *mainVC = [KYWeexVC vcWithUrlString:weexUrlString];
           KYNavigationController *nav = [[KYNavigationController alloc] 
initWithRootViewController:mainVC];
           [AppDelegate delegate].window.rootViewController = nav;
       }
   }
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to