2014-08-30 99 views
-1

我學習iOS的方法,並試圖建立一個實用工具類如下的Objective-C:不能實例化另一個類

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' 

什麼我做錯了錯誤?

回答

3

我剛剛意識到我失去了接口的基類。以下作品完美

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