代码之家  ›  专栏  ›  技术社区  ›  ChallengerGuy

使用Swift2从AppDelegate重新打开iOS应用程序到指定的导航控制器

  •  0
  • ChallengerGuy  · 技术社区  · 9 年前

    我正在使用Swift进行iOS项目。我有一个 ViewController 嵌入在 UINavigationController 。我的应用程序与 PDF 中的文件 plist 。用户可以打开 PDF格式 在项目中通过电子邮件发送给他们。我知道这会涉及到:

    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    
        if url != "" {
    
            // Load from Mail App
    
            incomingFileTransfer = url
    
            incomingStatus = "Incoming"
    
            /*let rootViewController = self.window!.rootViewController
            let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MainMenu") as! MainMenuViewController
            rootViewController?.navigationController?.popToViewController(setViewController, animated: false)*/
    
        } else {
    
            // Regular Load
    
            print("App Delegate: No incoming file")
    
            incomingFileTransfer = nil
    
        }  
    
        return true
    } 
    

    如果用户在应用程序的另一个区域,并且他们从 PDF格式 ,应用程序会打开回到他们所在的区域。我想让它对第一个装载的 视图控制器 总是我看了看 here 并试图在我上面的章节中实现这一点 AppDelegate 没有运气。有人能帮忙吗,特别是在斯威夫特?我不太擅长将Objective-C转换为Swift。

    我的 视图控制器 有一个 Title 设置为 MainMenu :

    enter image description here

    视图控制器 具有 UI导航控制器 设置为 Initial View 和的名字 Main :

    enter image description here

    这个 Storyboard 有一个 Storyboard ID 属于 主要的 UI导航控制器 Identity Inspector :

    enter image description here

    使现代化 :

    很抱歉这个 url 分配给全局 Variable 然后装入另一个 视图控制器 有一个 WebView .

    1 回复  |  直到 7 年前
        1
  •  0
  •   Community CDub    7 年前

    here 正如@NSGangster建议的那样,我 plist 并添加了以下内容:

    enter image description here

    现在我的应用程序重新打开,就像是第一次一样。