gpt4 book ai didi

swift - 从两个容器 View 保存数据

转载 作者:行者123 更新时间:2023-11-30 14:11:12 24 4
gpt4 key购买 nike

首先,我想为将使用的代码道歉。一般来说,我对编程完全陌生,它可能看起来像......:)

我的问题如下;

我有 1 个 ViewController (VC1),带有 2 个嵌入式容器 View (都是 TableViewController)。由于我想要为我的应用程序设计 UI 布局,我不能只使用 1 个 TableVieController。这两个容器 View 都有文本字段、标签、选择器 View ,需要用户提供数据。现在我想用 VC1 上的 1 个按钮保存所有这些数据。

一切都显示没有错误,但是当我点击“保存”按钮时,出现以下错误:无法将 AddRaptorTableVCContainerOne' (0x1099ad840) 类型的值转换为 AddRaptorTableVCContainerTwo' (0x1099ad270)。

提前致谢!

@IBAction func addRaptorSaveButton(sender: UIBarButtonItem) {

// Reference to childViewController

let childViewOne = childViewControllers.last as! AddRaptorTableVCContainerOne

let childViewTwo = childViewControllers.last as! AddRaptorTableVCContainerTwo


// Reference moc
let manObjCon = self.manObjCon
let addRaptorEntity = NSEntityDescription.entityForName("AddRaptorEntity", inManagedObjectContext: manObjCon!)

// Create instance of data model and initialize

var newRaptor = AddRaptorEntity(entity: addRaptorEntity!, insertIntoManagedObjectContext: manObjCon)

// Map our properties

newRaptor.image = UIImageJPEGRepresentation(self.addImageView.image, 1)
newRaptor.name = childViewOne.nameTextField.text
newRaptor.ringNo = childViewTwo.ringNoInputTextField.text


// Save our context

var error: NSError?

manObjCon!.save(nil)
println(newRaptor)

最佳答案

在两行中,您说的是 childViewControllers.last 是两个不同的东西。使用调试器或通过打印检查 childViewControllers 中的实际内容,然后选择正确的内容来转换为 AddRaptorTableVCContainerTwo

关于swift - 从两个容器 View 保存数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31747810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com