journalComment.delegate =self行上的警告:从不兼容的类型'JournalEntryViewController*‘向'id’赋值
journalComment是一个textView。
我不确定警告是关于什么的,它应该只是说-警告:“新手在键盘上,去上一些obj c课程。”
谢谢你的帮助。
- (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;
}发布于 2011-04-11 21:52:24
您的类必须符合UITextViewDelegate协议,因此在.h文件中使其看起来像
@interface JournalEntryViewController : NSViewController <UITextViewDelegate>
{
...
}然后,编译器将知道您的类符合该协议。当然,您仍然需要实现所需的方法。
发布于 2011-04-11 21:53:51
您从中发布示例代码的对象需要实现UITextViewDelegate协议。为此,您的.h文件应以以下内容开头:
@interface MyViewController : UIViewController <UITextViewDelegate>然后,您需要在.m文件中实现协议的方法(请参阅Apple Developer Docs)。这是必需的,但您可能会对一些委托回调函数感兴趣。
https://stackoverflow.com/questions/5622224
复制相似问题