菜鸟教程小白 发表于 2022-12-11 19:50:28

ios - NavigationController 中的 Swift ImagePicker


                                            <p><p>所以我在导航 Controller 内,想在按下按钮时显示一个图像选择器。这很好用,但是当我关闭选择器时,它会将我扔回 Root ViewController ,而不是我想要处理图像的地方。</p>

<p>这是我的代码:</p>

<pre><code>@IBAction func attachPhotoButtonPressed(sender: UIButton) {
      imagePicker.sourceType = .SavedPhotosAlbum
      presentViewController(imagePicker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: ) {
    if let image = info as? UIImage {
      print(&#34;Success&#34;)
    } else{
      print(&#34;Something went wrong&#34;)
    }

    self.dismissViewControllerAnimated(true, completion: nil)
}
</code></pre>

<p>我已经查看了这些问题,但没有找到解决方法。 (不是 Objective-C 的家伙)</p>

<p> <a href="https://stackoverflow.com/questions/10817305/pushing-a-navigation-controller-is-not-supported-performing-segues/23102975#23102975" rel="noreferrer noopener nofollow">Pushing a navigation controller is not supported- performing segues</a> </p>

<p> <a href="https://stackoverflow.com/questions/25444213/presenting-viewcontroller-with-navigationviewcontroller-swift" rel="noreferrer noopener nofollow">presenting ViewController with NavigationViewController swift</a> </p>

<p> <a href="https://stackoverflow.com/questions/17757072/pushing-a-navigation-controller-is-not-supported" rel="noreferrer noopener nofollow">Pushing a navigation controller is not supported</a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你跳到 Root ViewController 的原因是因为这条线</p>

<p><code>self.dismissViewControllerAnimated(true, completion: nil)</code></p>

<p>正在关闭父 View (自身),而不是选择器 View 。因此,假设您有对选择器的引用,那么您应该调用 </p>

<p><code>picker.dismissViewControllerAnimated(true, completion: nil)</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - NavigationController 中的 Swift ImagePicker,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44467079/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44467079/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - NavigationController 中的 Swift ImagePicker