0

I'd like to pass some object from one view (number 2) to view number 1. View 1 triggers view 2 and before that in "prepareForSeque" I'm passing "self" to the second view and store it in variable "delegate". After some time I'd like to pass back new created object to view 1 and I'm trying to achieve it but I got an error that method is not visible for this interface. How to pass created object to the mother view triggering method?

When I declare @property someObject and synthetize it, it works ok using delegate. Is there another option or am I forced to use delegate?

Code:

- (IBAction)saveAndClose:(id)sender {

    KwejkModel *mod = [[KwejkModel alloc] init];

    ((ViewController *)self.delegate).model = mod;

}

It works ok, but is there another option triggering method not using the property? Like this:

    [((ViewController *)self.delegate) someMethod];

but here is an error.

Here is my code:

VIEW 1

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"addItemSeque"]) {

        ScrollViewViewController *destViewController = segue.destinationViewController;
        destViewController.delegate = self;
    }
}

-(void) addNewPosition:(KwejkModel *)newKwejk
{
    //for testing only this
    [modelArray count];
}

VIEW 2:

- (IBAction)saveAndClose:(id)sender {

    KwejkModel *mod = [[KwejkModel alloc] init];

   // ((ViewController *)self.delegate).model = mod;

     //it crashes here with error:-[NSPlaceholderString initWithString:]: nil argument' but it sees method from VIEW 1
    [self.delegate addNewPosition:mod];
}
DKM
  • 270
  • 3
  • 13
  • "but here is an error." Could you please describe the error in more details? – Sergey Kalinichenko Jul 09 '14 at 19:26
  • I can not invoke mother method. Is it problem that I've forgotten to declare method in ".h" file? – DKM Jul 09 '14 at 19:28
  • Lets go to your MVC. What is your model that the view uses? I'm thinking we can create a class here that as acts as a datasource and than possibly use NSNotifications to inform the 1st view that the 2nd view has closed, or create a custom delegate here. – TheM00s3 Jul 09 '14 at 19:30
  • I've updated code for better view – DKM Jul 09 '14 at 19:38

1 Answers1

1

Try this link: Passing Data between View Controllers

Take a look at the first answer under Passing Data Back.

Community
  • 1
  • 1
Jeremy H
  • 452
  • 7
  • 20