ios - 如何在选取图像后执行 Segue
问题描述
我想在用户选择图像后(通过单击图像视图)执行 segue。
我已经检查了 segue id 并成功地连接了两个视图控制器。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// Executed when we select an image from the photo library.
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
// Sets the image to the image view (not really relevant because
// we push the user to the DetailVC, but let's leave it).
self.imageView.image = image
// Closing the image picker.
self.dismiss(animated: true, completion: nil)
// Performing segue (It doesn't perform!).
print("It gets to this point, but doesn't perform.")
self.performSegue(withIdentifier: "showDetail", sender: nil)
}
}
该程序将图像设置为图像视图,在“执行”功能之后获取该打印语句,但不执行segue。
解决方案
在情节提要中选择具有图像视图的视图控制器,在顶部有黄色圆圈右键单击从那里拖动到您想要继续的视图控制器并为其标识符提供 ID =“segueID”然后像这样编辑您的 didfinishpicking 方法
if let img = info[.originalImage] as? uiimage{
myimageview.image = img
dismiss(animated: true) {
self.performSegue(withIdentifier: “segueID”, sender: self)}}
推荐阅读
- sql-server - SYSUTCDATETIME() 在 2 毫秒内多次执行时,在事务中返回相同的结果
- django - 在 pythonanywhere 中项目部署期间发生错误
- pdf - 使用图像魔法转换 PDF,在周围留下额外的空白
- javascript - 如何在此示例中减少 JS 代码,同时保持相同的结果
- python - 无法打开包含文件:'mysql.h':没有这样的文件或目录
- sql - 如何在 SQL Server 中查找零值和负值
- typescript - 如何将类导出为只读但启用内部修改?
- database - 在 MongoDB 中,为什么非因果一致会话中的次要读取关注“可用”默认选项?
- jenkins - 从快照重新创建后,两个数字海洋水滴(Jenkins 和 App)之间的密钥对设置是否仍然有效?
- ruby-on-rails - 与自定义范围关联