我是iOS
新手。我的应用程序有多个视图控制器,因此我将代码抽象为
NavigationBar.h
@interface NavigationBar : NSObject
- (void) title: (NSString *) title withViewController: (UIViewController *) viewController;
@end
NavigationBar.m
#import "NavigationBar.h"
#import "PennyNavigationController.h"
@implementation NavigationBar
- (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)];
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[self getImageNamed:@"Add" withDimension:30] style:UIBarButtonItemStylePlain target:self action:@selector(sayHello:)];
}
- (IBAction)sayHello:(id)sender
{
NSLog(@"add new transaction");
}
- (void)btnClicked:(id)sender {
// NSLog(@"add new transaction");
}
当应用程序启动时,我点击Add
图片,我看不到日志,另外我看到该应用程序关闭。
我做错了什么?
P.S:似乎我在Add a custom selector to a UIBarButtonItem中完全提到过,但它仍然不起作用