大家好,使用图像选择器控制器选择图像

时间:2017-08-03 01:37:07

标签: ios image uitableview

  

当尝试在导航控制器上显示模态视图控制器时,导航控制器会在取消模式时弹出下面的所有视图控制器。

所以在推动一些视图控制器并在topViewController上显示一个模态后,当模态被解除时,我最终回到了rootViewController。

最近有人发生过这种情况,我似乎无法找到导致这种情况发生的原因吗?

func selectImageClicked(_ sender:UIButton)
{
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.allowsEditing = false

    let alert=UIAlertController(title: nil, message: "Select", preferredStyle: .actionSheet)

    let camera=UIAlertAction(  title: "Camera", style: .default) { (action) in
         imagePicker.sourceType = .camera

        DispatchQueue.main.async {
            self.present(imagePicker, animated: true, completion: nil)
        }
    }
    let gallery=UIAlertAction(  title: "Gallery", style: .default) { (action) in
        imagePicker.sourceType = .photoLibrary

        DispatchQueue.main.async {
            self.present(imagePicker, animated: true, completion: nil)
        }
    }
    let cancel=UIAlertAction(  title: "Cancel", style: .cancel) { (action) in
    }

    alert.addAction(camera)
    alert.addAction(gallery)
    alert.addAction(cancel)

    present(alert, animated: true, completion: nil)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
    if (info[UIImagePickerControllerOriginalImage] as? UIImage) != nil
    {

        objectAuctionItemDetail.itemImage = info[UIImagePickerControllerOriginalImage] as! UIImage

    }

    DispatchQueue.main.async {
         picker.dismiss(animated: true, completion: nil)

        self.tblTableView.reloadData()
     }
}

0 个答案:

没有答案