Objective-C:无法实例化另一个类的方法

时间:2014-08-30 04:50:31

标签: ios objective-c

我正在学习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'  

我做错了什么?

1 个答案:

答案 0 :(得分:3)

我刚刚意识到我缺少接口的基类。以下工作完美

@interface Common: NSObject
- (void) title: (NSString *) title withViewController: (UIViewController *) viewController;
@end