Obj C - UITextViewDelegate 不兼容类型警告

发布于 2024-10-31 17:22:48 字数 849 浏览 0 评论 0原文

关于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

允世 2024-11-07 17:22:48

您的类必须符合 UITextViewDelegate 协议,因此在您的 .h 文件中使其看起来像

@interface JournalEntryViewController : NSViewController <UITextViewDelegate>
{

...

}

这样 然后编译器就会知道您的类符合该协议。当然,您仍然需要实现所需的方法。

Your class must conform to the UITextViewDelegate protocol, so in your .h file make it look like

@interface JournalEntryViewController : NSViewController <UITextViewDelegate>
{

...

}

Then the compiler will know that your class conforms to that protocol. Of course, you still need to implement the needed methods.

沧桑㈠ 2024-11-07 17:22:48

您发布示例代码的对象需要实现 UITextViewDelegate 协议。为此,您的 .h 文件应以以下内容开头:

@interface MyViewController : UIViewController <UITextViewDelegate>

在 .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:

@interface MyViewController : UIViewController <UITextViewDelegate>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文