Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode error: No known instance method for selector

I need help debugging my class. I am getting an error so bizarre that I couldn't find anything similar, so I'm just going to put down most of my code.

//Tab.h
#import <UIKit/UIKit.h>
@class Tab;
@protocol TabDelegateDataSource <NSObject>
@required
-(void)removeTab:(Tab *)tab;
@end

@interface Tab : UIView
{
     id <TabDelegateDataSource> __strong _delegate;
}

@property(strong) id <TabDelegateDataSource> delegate;

-(void)removeTab;

@end

//  Tab.m
#import "Tab.h"
@implementation Tab
@synthesize delegate = _delegate;
-(void)removeTab
{
    [self.delegate removeTab:self];//Error here saying: No known instance method for selector 'removeTab:'  
}

@end
like image 693
Jordan Medlock Avatar asked Dec 05 '11 15:12

Jordan Medlock


1 Answers

I can now recreate and fix this error at will.

Make sure that the .h header where this is defined ...

@protocol TabDelegateDataSource <NSObject>
-(void)removeTab:(Tab *)tab;
@end

... is included wherever you plan to use the delegate, e.g. somewhere at the top of the .m source that includes this:

[self.delegate removeTab:self]

If the compiler has only seen a forward definition of TabDelegateDataSource like this:

@protocol TabDelegateDataSource;

You'll get the error:

error: no known instance method for selector 'removeTab:'

and not the more expected forward definition related error

like image 128
dpjanes Avatar answered Sep 21 '22 21:09

dpjanes