Question

I'm getting the above error, and I don't know why. The line where the error is flagged is:

- (IBAction)cancelButton:(UIBarButtonItem *)sender
{    
    [self.delegate addActivityViewControllerDidCancel:self.thisActivity];
}

I'm confused because there seems to be no problem with this method, immediately preceding:

- (IBAction)saveButton:(UIBarButtonItem *)sender
...          
    [self.delegate addViewControllerDidSave];
}
...       
}

My protocol is declared like this in the associated header file:

@protocol AddActivityViewControllerDelegate <NSObject>

-(void) addViewControllerDidSave;

-(void) addViewControllerDidCancel:(WMDGActivity *) activityToDelete;

@end

and the methods are implemented like this in the delegate object:

-(void) addActivityViewControllerDidSave
{
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    [localContext MR_saveToPersistentStoreAndWait];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self refreshData];

}

-(void) addActivityViewControllerDidCancel:(WMDGActivity *) activityToDelete
{
    [activityToDelete MR_deleteEntity];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self refreshData];

}

Can someone please point out my mistake?

Edit:

There is indeed a naming problem (I was pasting in from a test app). However, I have corrected it, I believe, like so:

@protocol AddActivityViewControllerDelegate <NSObject>

-(void) AddActivityViewControllerDidSave;

-(void) AddActivityViewControllerDidCancel:(WMDGActivity *) activityToDelete;

@end

And

- (IBAction)saveButton:(UIBarButtonItem *)sender

{
...
    [self.delegate AddActivityViewControllerDidSave];
...
}

And

- (IBAction)cancelButton:(UIBarButtonItem *)sender
{    
    [self.delegate addActivityViewControllerDidCancel:self.thisActivity];
}

And

-(void) addActivityViewControllerDidSave
{
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    [localContext MR_saveToPersistentStoreAndWait];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self refreshData];

}

-(void) addActivityViewControllerDidCancel:(WMDGActivity *) activityToDelete
{
    [activityToDelete MR_deleteEntity];
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [self refreshData];

}

Still getting error.

Build fails even with breakpoint suggested by @Leo

Was it helpful?

Solution

There are a couple problems with your code:

  • Your protocol defines method names without the word Activity, but your implementation defines method names with the word Activity, so those method names do not match. You can rely on completion or copy-paste to implement a protocol method and be sure the method signature matches.
  • self.delegate may simply be type id, which does not conform to a specific protocol. The compiler has no way of knowing that self.delegate can respond to your protocol methods. Change that line to:

    [(id<AddActivityViewControllerDelegate>)self.delegate addActivityViewControllerDidCancel:self.thisActivity];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top