从两个containerview保存数据

时间:2015-07-31 13:48:44

标签: swift ios8 container-view

首先,我为将要使用的代码道歉。我对编程一般都是全新的,它可能看起来像.... :)

我的问题如下;

我有1个ViewController(VC1),带有2个嵌入式容器视图(两个TableViewControllers)。对于我的应用程序我想要的UI布局,我不能只使用1个TableVieController。这两个容器视图都具有文本字段,标签,需要由用户提供数据的选择视图。 现在我想用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)

1 个答案:

答案 0 :(得分:0)

在两行中,你说childViewControllers.last是两回事。使用调试器或打印检查childViewControllers中的实际内容,然后选择正确的内容作为AddRaptorTableVCContainerTwo