2011-04-11 52 views
0

警告与journalComment.delegate =自行:分配来自不兼容的类型的 'id' 'JournalEntryViewController *'的OBJÇ - UITextViewDelegate不兼容的类型警告

journalComment是一个TextView。

我不确定警告是什么,它应该只是说 - 警告:“键盘上的newb,去一些对象类。”

谢谢你的帮助。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
     // Hide keyboard when done key is pressed 

     // define the area and location for the UITextView 
     CGRect tfFrame = CGRectMake(0, 0, 320, 460); 
     journalComment = [[UITextView alloc] initWithFrame:tfFrame]; 
     // make sure that it is editable 
     journalComment.editable = YES; 

     // add the controller as the delegate 
     journalComment.delegate = self; 

    } 
    return self; 
} 

回答

10

你的类必须符合UITextViewDelegate协议,所以在您的.h文件中,使它看起来像

@interface JournalEntryViewController : NSViewController <UITextViewDelegate> 
{ 

... 

} 

编译器会知道你的类遵循该协议。当然,你仍然需要实现所需的方法。

+0

接口既可以是? – rd42 2011-04-11 15:09:15

+0

nevermind http://stackoverflow.com/questions/4361148/objective-c-multiple-delegates – rd42 2011-04-11 15:10:53

3

您发布示例代码的对象需要实现UITextViewDelegate协议。要做到这一点,你的.h文件中应开始:

@interface MyViewController : UIViewController <UITextViewDelegate> 

在您.m文件,然后你需要实现您对协议的方法(见Apple Developer Docs)。没有任何要求,但是您可能对某些委托回调感兴趣。

相关问题