2014-10-28 71 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