【发布时间】:2017-08-29 05:23:49
【问题描述】:
我想将照片数据从 Tabbarcontroller 中的一个 Viewcontroller(cameraVC) 传递到同一 Tabbarcontroller 中的另一个 Viewcontroller(mainVC)在执行 segue 后不会丢失标签栏。
设置: *标签栏控制器
-Navbarcontroller
--mainVC (Tabbar Item)
--cameraVC (Tabbar Item)
我必须能够在 cameraVC 中使用 prepareForSegue 和 performSegue(这就是我将数据传递给 mainVC 的方式)。
我所尝试的 W/O 成功: Keeping tab bar on View after segue?, Why TabBar hides after the segue?
当前实施:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationNavigationController = segue.destination as! UINavigationController
let targetController = destinationNavigationController.topViewController as! HomeVC
// if let homeVC = segue.destination as? HomeVC {
if let imageDict = sender as? Dictionary<String, Any> {
let imageData = imageDict["snapshotData"]
targetController.imageData = imageData as? Data
// }
}
}
@IBAction func sendBtnPressed(_ sender: Any) {
performSegue(withIdentifier: "goFeed", sender: ["snapshotData": photoData.removeValue(forKey: "photoData")])
imageTaken.image = nil
self.view.insertSubview(previewView, aboveSubview: imageView)
}
【问题讨论】:
-
需要传递多少图片数据?
-
一次一张图片
-
如果要传递单个图像,则无需将
Data传递给下一个 vc,只需将图像直接传递给下一个 vc 的类似对象即可。 -
我必须传递数据,因为数据将用于发布到我的数据库
标签: ios swift uitabbarcontroller