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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With