我正在学习iOS
并尝试创建一个实用程序类,如下所示
COMMON.H
@interface Common
- (void) title: (NSString *) title withViewController: (UIViewController *) viewController;
@end
Common.m
#import "Common.h"
#import "PennyNavigationController.h"
@implementation Common
- (void)title:(NSString *)title withViewController:(UIViewController *)viewController {
viewController.title = title;
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Menu"
style:UIBarButtonItemStyleBordered
target:(PennyNavigationController *) viewController.navigationController
action:@selector(showMenu)];
}
@end
然后我尝试在我的TableViewController
中使用
#import "Common.h"
- (void)viewDidLoad {
[super viewDidLoad];
Common *common = [[Common alloc] init];
}
我的IDE上出现错误
Cannot resolve method 'alloc' for interface 'Common'
我做错了什么?
答案 0 :(得分:3)
我刚刚意识到我缺少接口的基类。以下工作完美
@interface Common: NSObject
- (void) title: (NSString *) title withViewController: (UIViewController *) viewController;
@end