【问题标题】:From one VC to another VC but after that everything hang从一个 VC 到另一个 VC 但在那之后一切都挂了
【发布时间】:2018-04-20 10:13:31
【问题描述】:

您好,我设法使用以下代码从TopVC 转到BottomVC。但在那之后我的bottomVC 将无法工作。点击链接时BottomVC 不会前进。

编辑的答案

Top 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

【问题讨论】:

  • 这里你设置了错误的值
  • Top VC 我用下面的代码去bottomVC,我到底是去BottomVC还是BottomClass? -- 这段代码带你去 BottomVC
  • 嘿哥们现在试试。
  • RB1509 我认为这不是我的segue,如果我正常导航到我的bottomVC,它将正确显示。我认为这是我向bottomVC 展示的方式。我现在正在尝试@ketaki Damale 的建议,但非常感谢,非常感谢您的帮助。

标签: ios objective-c uiviewcontroller


【解决方案1】:

替换

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

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

注意:- 您只在 TopVC 上呈现 bottomVC。因此 rootViewController 仍然是 TopVC。因此,当您调用 performSegueWithIdentifier 时,它会为 bottomVC 获取 nil 对象。

试试这个..

【讨论】:

  • 还是不去bottomVC我得到了以下错误2018-04-20 19:37:18.541302+0800 SFITNESS[62196:5508216] -[More fromClassBook:]: unrecognized selector sent to instance 0x7fc289713270 2018-04-20 19:37:18.541549+0800 SFITNESS[62196:5508216] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: &lt;NSInvalidArgumentException&gt; -[More fromClassBook:]: unrecognized selector sent to instance 0x7fc289713270
  • 是不是因为它嵌入在 TabBarController 然后是 NavigationController 然后是下一个 VC?
猜你喜欢
  • 2020-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
  • 2017-12-18
  • 2017-12-10
  • 1970-01-01
相关资源
最近更新 更多