'Warning "Method definition not found" in Objective-C. Call Method from Category file
I have created some method in category file. I just want to reuse those methods in my view controllers. So I have imported that category file in view controllers and declared the method in header file also. calling it like this:
Category class:
@interface UIViewController (headerView)
-(UILabel *)someMethod;
@implementation UIViewController (headerView)
-(UILabel *)someMethod{
}
HomeViewController:
@interface HomeViewController : UIViewController
-(UILabel *)someMethod;
@implementation HomeViewController
[self someMethod];
I am getting warning message in this line:
@implementation HomeViewController
It's working. But I want to clear this warning. How can I do it?
Solution 1:[1]
If you want you category in view controller do it something like that
Your category
@interface UIViewController (ExtendedMethods)
- (void)someMethod;
@end
@implementation UIViewController (ExtendedMethods)
- (void)someMethod {
NSLog(@"Some method");
}
@end
MyViewController.m
#import "MyViewController.h"
#import "UIViewController+ExtendedMethods.h"
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self someMethod];
}
@end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Konstantin |
