2014-10-28 37 views
0

在PSPoemsViewController.h我有一个协议,声明如下:IOS 6的Xcode警告协议是没有意义的

@protocol PSPoemsViewControllerDelegate <NSObject> 

- (void) savePoem:(Poem *)thePoem withText:(PSTextStorage *)theText; 

@end 

,并在.m文件我有它的声明:

- (void) savePoem:(Poem *)thePoem withText:(PSTextStorage *)theText; 
{ 
... 
} 

在PSVersionViewController。 h I类有:

@interface PSVersionViewController : UIPageViewController <PSPoemsViewControllerDelegate, UIPageViewControllerDataSource> 

当我编译该编译器会引发警告:

/Users/Keith/Documents/My Projects/Poem Shed/Poem Shed/PSVersionViewController.m:28:17: Method 'savePoem:withText:' in protocol 'PSPoemsViewControllerDelegate' not implemented

事情是代码执行并找到应该丢失的方法。但是有一个奇怪的问题 - 即使没有中断设置,它有时会断开方法,然后崩溃。这暗示着某种腐败。我试过做一个干净的构建,删除方法并将其放回,但没有任何改变警告。我正在使用Xcode 6.1(它在测试版上也失败了)。

+0

不声明在PSPoemsViewController委托方法......你只要调用它... – CW0007007 2014-10-28 13:05:12

+0

当然该方法需要从委托调用(PSVersionViewController)并在主类(PSPoemsViewController)中声明,该类也声明协议。 – easiwriter 2014-10-28 13:12:54

+0

你调用它,但你没有像上面那样实现它..请参阅下面的答案。 – CW0007007 2014-10-28 13:16:11

回答

0

所以:

@protocol PSPoemsViewControllerDelegate <NSObject> 

- (void) savePoem:(Poem *)thePoem withText:(PSTextStorage *)theText; 

@end 

@interface PSPOemsViewController : UIViewController 

@property (weak) id < PSPoemsViewControllerDelegate> delegate; 

@end 

然后在PSPoemsViewController.m当你想调用这个方法调用:在符合该委托添加方法的类

//Check that the delegate is set and that it has implemented the method. 
if ([self.delegate respondsToSelector:@selector(savePoem:withText:)]) 
    [self.delegate savePoem:YOUR_POEM withText:@"]; 

然后。所以在你的PSVersionViewController。确保你也设置了委托。

PSPoemsViewController *anInstanceofPoemsViewController = ..... 
[anIntanceOfPoemsViewController setDelegate:self]; 

然后添加方法:

- (void) savePoem:(Poem *)thePoem withText:(PSTextStorage *)theText; 
{ 
... 
} 
+0

谢谢。这真是愚蠢! – easiwriter 2014-10-28 13:20:38

+0

没问题..... – CW0007007 2014-10-28 13:40:42