开发者

Obj C - UITextViewDelegate incompatible type warning

开发者 https://www.devze.com 2023-02-23 08:02 出处:网络
Warning on the line with journalComment.delegate = self:Assigning to \'id\' from incompatible type \'JournalEntryViewController*\'

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 sur开发者_如何转开发e that it is editable
        journalComment.editable = YES;

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

    }
    return self;
}


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号