嗨,我设法通过使用以下代码从TopVC转到BottomVC。但是之后,我的bottomVC将无法使用。单击链接后,BottomVC将不会继续前进。

ios - 从一个VC到另一个VC,但是之后一切都挂起了-LMLPHP

编辑答案

顶级VC我使用以下代码转到bottomVC,实际上我是转到BottomVC还是BottomClass?

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"BuyCredit"];
    vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [[self navigationController] pushViewController:vc animated:YES];

    UINavigationController* classesNav = (UINavigationController*)self.tabBarController.viewControllers[4];
    BuyCredit *classesViewController = [classesNav.viewControllers firstObject];
    [classesViewController fromClassBook:sURL];

底部VC假定在单击链接时加载另一个VC,但是一切都挂起了
- (void)viewDidLoad {

    [super viewDidLoad];

    sURL = self.urlString;

    NSLog(@"Receiving From and the sURL :  %@", sURL);

    NSURL *url = [NSURL URLWithString:sURL];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [webView setDelegate:(id<UIWebViewDelegate>)self];
    [webView loadRequest:urlRequest];

}

- (void)fromClassBook:(NSString*)string {

    sURL = string;
    NSLog(@"Please pass over **** %@", sURL);

    NSURL *url = [NSURL URLWithString:sURL];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    [webView setDelegate:(id<UIWebViewDelegate>)self];
    [webView loadRequest:urlRequest];

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    PurchaseDet *target = segue.destinationViewController;

    if ([segue.identifier isEqualToString:@"PurchaseDet"]) {

        target.urlString = sURL;

    }
}


- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    NSURL *URL = [request URL];
    NSString *theString = [URL absoluteString];
    NSRange match;

    NSLog(@"Detect the URL theString :  %@", theString);

    match = [theString rangeOfString: @"PHPSMI"];

    //--- If the URL string does not contain purchase_det.asp meaning it will load the webview
    if (match.location == NSNotFound) {
        sURL = theString;
        return YES; //--- Load webview

    } else {  //--- Because currently the purchase confirm page is just another page, hence will reload the current webview.

        NSLog(@"Will pass to SEQUE and called the URL :%@",theString);
        //--- Calling this method will tell the segue hey I want to redirect to another viewController.
        //--- Update the sURL with the latest String
        sURL = theString;

        [self performSegueWithIdentifier:@"PurchaseDet" sender:self];

        return NO; // Don't load the webview, capture the sURL and trigger NewsDet segue, and then pass sURL as urlstring to destination VC
    }

}
@end

最佳答案

更换
[self presentViewController:vc animated:YES completion:NULL];

[[self navigationController] pushViewController:vc animated:YES];

注意:-
您仅在TopVC上显示bottomVC。因此rootViewController仍为TopVC。因此,当您调用performSegueWithIdentifier时,它将为bottomVC获取nil对象。

尝试这个..

关于ios - 从一个VC到另一个VC,但是之后一切都挂起了,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49939270/

10-09 16:23