2017-09-20 23 views
1

这是我的第一个问题,希望它不会太愚蠢。由于另一个呈现的视图没有完成,视图控制器不显示。

这里是我的应用程序:
VC1
VC2 - ChatTableViewController
VC3 - PopupPhotoSourceVC

VC1 - 一个按钮呈现VC2模态
VC2 - 一个 “栏” 按钮,模态呈现VC3 (VC3演示设置为“过电流上下文”)
VC2 - 设置展开顺序

@IBAction func unwindToChatTableViewController(segue: UIStoryboardSegue) { 

    attachPhotoButtonFinish() 
} 

VC3 - 中间的两个按钮,均设置为上方,通过拖动并使用StoryBoard进行选择来放松静止。

内VC3,使用SEGUE准备让VC2知道用户选择

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    let destChatViewController = segue.destination as! ChatTableViewController 


    if segue.identifier == "library" // library Button 
    { 
     print("set cameraType to library from popupviewcontroller") 
     let time = getCurrentTime() 
     print("==== timer start ====== \(time.3):\(time.4):\(time.5)") 

     destChatViewController.cameraType = "library" 
    } 
    else if segue.identifier == "newphoto" // newphoto Button 
    { 
     print("set cameraType to newphoto from popupviewcontroller") 
     let time = getCurrentTime() 
     print("==== timer start ====== \(time.3):\(time.4):\(time.5)") 

     destChatViewController.cameraType = "newphoto" 
    } 

    // for unwind segue, no need to call dismiss 
    print("not calling dismiss pop up") 
    let time = getCurrentTime() 
    print("==== timer start ====== \(time.3):\(time.4):\(time.5)") 

    //dismiss(animated: true, completion: nil) 
} 

里面VC2,attachPhotoButtonFinish将尝试根据用户的选择

func attachPhotoButtonFinish() { 

    print("attachphotobutton start") 
    let time = getCurrentTime() 
    print("==== timer start ====== \(time.3):\(time.4):\(time.5)") 


    let image = UIImagePickerController() 
    image.delegate = self 

    if cameraType == "library"{ 
     image.sourceType = UIImagePickerControllerSourceType.photoLibrary 

    } 
    else if cameraType == "newphoto"{ 
     image.sourceType = UIImagePickerControllerSourceType.camera 
     image.cameraCaptureMode = .photo 
    } 
    else{ 
     print("Something wrong!!!") 
     return 
    } 
    image.allowsEditing = false 
    image.modalPresentationStyle = .overCurrentContext 

    print("calling imagepicker") 
    let time1 = getCurrentTime() 
    print("==== timer start ====== \(time1.3):\(time1.4):\(time1.5)") 

    self.present(image, animated: true, completion: nil) 
} 

而且我也来调用图像选取器控制器尝试打印VC3的脱硝时间

deinit{ 
    print("===== \(self.classForCoder.description()) be deinit") 
    let time = getCurrentTime() 
    print("==== timer start ====== \(time.3):\(time.4):\(time.5)") 

} 

关于运行结果,有时(1/10)VC3在VC2之前完成图像选择器。所以我可以看到它正确显示。

====定时器启动====== 18时34分58秒
没有要求解雇弹出
====定时器启动====== 18时34分58秒
放松到ChatTableViewController cameraType =库
====定时器启动====== 18时34分58秒
attachphotobutton开始
====定时器启动====== 18时34分58秒
来电图片选择器
====定时器启动====== 18:34:58
===== PhotoStreamSourceTest.PopupPhotoSourceVC is deinit
==== timer start ====== 18:34:59
2017-09-20 18:34:59.274464 + 0800 PhotoStreamSourceTest [14690:399530] [AXRun-PID]客户端请求取消挂起PID:14706名称:
2017-09-20 18:34:59.283271 + 0800 PhotoStreamSourceTest [14690:399463] [MC] systemgroup.com.apple.configurationprofiles路径的系统组容器是/Users/_/Library/Developer/CoreSimulator/Devices/54B3F249-2C6A-4C18-B2E1-C7271199A7CF/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-09-20 18:34:59.284012 +0800 PhotoStreamSourceTest [14690:399463] [MC]从私人有效用户设置读取。

但大部分时间,我收到下面的结果和图像选择器不显示。

====定时器启动====== 18点35分48秒
没有要求解雇弹出
====定时器启动====== 18点35分48秒
放松到ChatTableViewController cameraType =库
====定时器启动====== 18时35分48秒
attachphotobutton开始
====定时器启动====== 18时35分48秒
来电图片选择器
====定时器启动====== 18:35:48
2017-09-20 18:35:48.967515 + 0800 PhotoStreamSourceTest [14690:400836] [AXRun-PID]客户端请求取消挂起PID:14706名称:
2017-09-20 18:35:49.049357 + 0800 PhotoStreamSourceTest [ 14690:399463]警告:正在进行演示时尝试呈现!
===== PhotoStreamSourceTest.PopupPhotoSourceVC被DEINIT
====定时器启动====== 18点35分49秒

谢谢!

+0

看看这个[意义的警告“,而演示文稿正在进行!”](https://stackoverflow.com/a/17120065/4056108) – chirag90

+1

@ chirag90感谢您的及时答复。我只是想知道是否放松继续不适合这种情况。确保在调用图像选择器之前关闭VC3是绝对的规则。 – Hungo

+0

对不起,我只是在帮助警告 – chirag90

回答

0

感谢@ chirag90的链接 Meaning of Warning “while a presentation is in progress!

的关键点是使用驳回方法的完成块,以确保VC3是真正关闭之前我们让VC2推出图像拾取。

以下解决方案使用委托代替unwind segue。如果有人有其他方法,请让我知道!谢谢!

首先,在VC3上,从Storyboard中删除两个按钮上的unwind segue。然后在两个按钮称为libraryButtonPressed()和takePhotoButtonPressed()

在VC3添加IBAction为:PopupPhotoSourceVC,添加一个协议

protocol PopupPhotoSourceVCDelegate { 
func finishPassing(string: String)} 

在VC3还添加型

var delegate: PopupPhotoSourceVCDelegate? 

的代表可变现在在VC2上采用协议

class ChatTableViewController: UITableViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, PopupPhotoSourceVCDelegate{ 

并执行th ËfinishPassing功能的遵守协议

func finishPassing(string: String) { 
    cameraType = string 
    attachPhotoButtonFinish() 
} 

不要忘了委托设置为自

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let destination = segue.destination as? PopupPhotoSourceVC{ 
     destination.delegate = self 
    } 
} 

现在,回到VC3,让我们实现的关键方法

@IBAction func libraryButtonPressed(_ sender: UIButton) { 
    dismiss(animated: true) { 
     self.delegate?.finishPassing(string: "library") 
    } 

} 
@IBAction func takePhotoButtonPressed(_ sender: UIButton) { 
    dismiss(animated: true) { 
     self.delegate?.finishPassing(string: "newphoto") 
    } 
} 

这两个方法将关闭VC3:PopupPhotoSourceVC,并在解散实际完成后,然后在VC2:ChatTableViewController中调用finishPassing来启动启动图像选择器。

希望得到这个帮助,谢谢。

相关问题