0

First of all i wanne apologize for the code that will be used. I'am completely new to programming in general and it probably looks like .... :)

My problem is the following;

I have 1 ViewController (VC1) with 2 embedded container views (both TableViewControllers). Causs of the UI layout i want for my app i couldn't just use 1 TableVieController. Both of these container views have Textfields, labels, pickerviews that needs to be provided with data by the user. Now i want to save all this data with 1 button from the VC1.

Everything displays without error but when i tap the save button is gives me the following error: Could not cast value of type AddRaptorTableVCContainerOne' (0x1099ad840) to AddRaptorTableVCContainerTwo' (0x1099ad270).

Thanks in advance!

@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)
DavyG
  • 21
  • 2

1 Answers1

0

In two lines, you're saying that childViewControllers.last is two different things. Check whats actually in childViewControllers, using the debugger or by printing, and pick the right thing to cast as AddRaptorTableVCContainerTwo.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • (+1) Thank you i overlooked that double .last. Even i triple- checked everything! // Cause i'am new on this i can't display the +1 – DavyG Aug 04 '15 at 23:04