解雇UIImagePicker

时间:2016-04-18 08:41:17

标签: ios swift uiimagepickercontroller viewcontroller

我正在使用以下方式解雇我的UIImagePicker:

func imagePickerControllerDidCancel(picker: UIImagePickerController!)
     {
      picker.dismissViewControllerAnimated(true, completion: nil)
     }

不幸的是,这也消除了下面的观点。我不希望这种情况发生。

我已经像这样加载了UIImagePicker:

let imagePicker: UIImagePickerController! = UIImagePickerController()


 @IBAction func uploadFromAlbumButton(sender : UIButton){
    let picker = UIImagePickerController()
    picker.allowsEditing = true
    picker.delegate = self
    presentViewController(picker, animated: true, completion: nil)
}

UIImagePicker下面的视图显示如下:

let newViewController = FulfilWishViewController();
newViewController.delegate = self
navigationController?.pushViewController(newViewController, animated: true)    

2 个答案:

答案 0 :(得分:0)

请检查您是否在viewwillappear()中执行了任何代码。因为在解除了UIImagepickerController之后,它调用了父控制器的viewwillappear()。

答案 1 :(得分:0)

据我所知,你应该有下一个结构: Storyboard 此外,SecondViewController应该具有故事板ID enter image description here

您的ViewController.swift:

class ViewController: UIViewController, UINavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func didTapBtn1(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let secondViewController = storyboard.instantiateViewControllerWithIdentifier("SecondViewController")
        self.navigationController?.pushViewController(secondViewController, animated: true)
    }
}

SecondViewController.swift:

class SecondViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func didTapBtn2(sender: AnyObject) {
        let picker = UIImagePickerController()
        picker.allowsEditing = true
        picker.delegate = self
        presentViewController(picker, animated: true, completion: nil)
    }

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        picker.dismissViewControllerAnimated(true, completion: nil)
    }
}

此代码已经过测试。我认为,问题在于调用SecondViewController。

<强>更新

如果您使用的是xib,那么您可以通过以下方式调用SecondViewcontroller:

@IBAction func didTapBtn1(sender: AnyObject) {
    let secondViewController = SecondViewController(nibName: "SecondViewController", bundle: nil)
    self.navigationController?.pushViewController(secondViewController, animated: true)
}
在ParentViewController中