从主故事板显示视图控制器

时间:2018-04-17 10:47:36

标签: swift xcode uiviewcontroller case

我的一个Swift文件中有一个 case .editProfile: vc = PoiDetailViewController() self.navigationController?.popViewController(vc,animated: true) ,它运行以下方法:

PoiDetailViewController

当我运行代码时它似乎不起作用。

视图控制器位于主故事板上,我希望在调用此案例时显示try { System.out.println(" Image is Processing :: " + assetDetails.getName() + "Original Size :: " + assetDetails.getSize()); ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\ImageMagick-6.9.9-Q16\\convert.exe", "-quality", "85%", assetDetails.getAssetNode().getPath(), assetDetails.getAssetNode().getPath()); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } System.out.println(p.waitFor()); session.save(); } catch (final IOException | RepositoryException | InterruptedException ex) { ex.printStackTrace(); }

2 个答案:

答案 0 :(得分:0)

根据我的理解,你需要弹出特定的View Controller,如果它在堆栈中,如果没有,那么你需要推送到那个控制器

var loginVCFound:Bool = false;

    let navigationController : UINavigationController! = self.window!.rootViewController as! UINavigationController;
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil);

    let viewControllers: [UIViewController] = navigationController.viewControllers
    for aViewController in viewControllers {
        if aViewController is LoginVC {// Pass the name of your controller here
            loginVCFound = true;
            navigationController.popToViewController(aViewController, animated: true)
            break;
        }
    }
    if !loginVCFound { // change the identifier and VC with yours
        let objLoginVC = mainStoryboard.instantiateViewController(withIdentifier: "LoginVC") as! LoginVC
        navigationController.pushViewController(objLoginVC, animated: true)
    }

答案 1 :(得分:0)

如果我理解正确,您应该能够在代码中通过present实现您正在寻找的内容。像这样:

  case .editProfile:
    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc = storyBoard.instantiateViewController(withIdentifier: "PoiDetailViewController") // or whatever identifier you have given it
    self.present(vc, animated: true, completion: nil)

但是,确保您在身份检查器中为视图控制器设置故事板ID。

不需要任何分段。

要设置故事板ID,请单击要使用的View Controller(在本例中为PoiDetailViewController),然后单击身份检查器图标并设置它所要求的故事板ID。我附上了一张图片,以便您可以看到它需要去的地方(在标有'故事板ID'的字段中)

Identity inspector

希望有所帮助。