Obj C - UITextViewDelegate 不兼容类型警告
关于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;
}
Warning on the line with journalComment.delegate = self: Assigning to 'id' from incompatible type 'JournalEntryViewController*'
journalComment is a textView.
I'm not sure what the warning is about, it should just say - warning: "newb at keyboard, go take some obj c classes."
Thank you for any help.
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的类必须符合
UITextViewDelegate
协议,因此在您的 .h 文件中使其看起来像这样 然后编译器就会知道您的类符合该协议。当然,您仍然需要实现所需的方法。
Your class must conform to the
UITextViewDelegate
protocol, so in your .h file make it look likeThen the compiler will know that your class conforms to that protocol. Of course, you still need to implement the needed methods.
您发布示例代码的对象需要实现 UITextViewDelegate 协议。为此,您的 .h 文件应以以下内容开头:
在 .m 文件中,您需要实现协议的方法(请参阅 Apple 开发人员文档)。没有任何必需的,但无论如何您可能对某些委托回调感兴趣。
The object from which you posted the sample code needs to implement the UITextViewDelegate protocol. To do that, your .h file should start with:
In your .m file, you then need to implement your methods for the protocol (see Apple Developer Docs). There aren't any which are required, but you may be interested in some of the delegate callbacks anyway.