我收到了上述错误,我不知道为什么。标记错误的行是:
- (IBAction)cancelButton:(UIBarButtonItem *)sender
{
[self.delegate addActivityViewControllerDidCancel:self.thisActivity];
}
我很困惑,因为这个方法似乎没有问题,紧接在前面:
- (IBAction)saveButton:(UIBarButtonItem *)sender
...
[self.delegate addViewControllerDidSave];
}
...
}
我的协议在关联的头文件中声明如下:
@protocol AddActivityViewControllerDelegate <NSObject>
-(void) addViewControllerDidSave;
-(void) addViewControllerDidCancel:(WMDGActivity *) activityToDelete;
@end
并且这些方法在委托对象中实现如下:
-(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];
}
有人可以指出我的错误吗?
修改
确实存在命名问题(我从测试应用程序中粘贴)。但是,我相信,我已经纠正了这个问题:
@protocol AddActivityViewControllerDelegate <NSObject>
-(void) AddActivityViewControllerDidSave;
-(void) AddActivityViewControllerDidCancel:(WMDGActivity *) activityToDelete;
@end
并且
- (IBAction)saveButton:(UIBarButtonItem *)sender
{
...
[self.delegate AddActivityViewControllerDidSave];
...
}
和
- (IBAction)cancelButton:(UIBarButtonItem *)sender
{
[self.delegate addActivityViewControllerDidCancel:self.thisActivity];
}
和
-(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];
}
仍然出现错误。
即使@Leo建议使用断点
,构建也会失败答案 0 :(得分:4)
您的代码存在一些问题:
self.delegate
可能只是类型id
,不符合特定协议。编译器无法知道self.delegate
可以响应您的协议方法。将该行更改为:
[(id<AddActivityViewControllerDelegate>)self.delegate addActivityViewControllerDidCancel:self.thisActivity];