我想在我的 UINavigationController 中添加一个 UIBarButton。我在以下代码的帮助下做到了,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *rootController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *addInfoButton = [[UIBarButtonItem alloc] initWithTitle:@"Add Info" style:UIBarButtonItemStylePlain target:self action:@selector(addCustomerInfo)];
self.navigationItem.rightBarButtonItem = addInfoButton;
}
-(void) addCustomerInfo
{
AddInfoViewController *addVC = [[AddInfoViewController alloc] initWithNibName:@"AddInfoViewController" bundle:nil];
[addVC setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addVC animated:YES];
}
我应该-(void) addCustomerInfo
在 .h 文件中声明“”吗?我已经尝试过了,但没有运气。
代码仍然抛出异常,
2012-08-06 04:16:22.200 TableView[5698:f803]-[RootViewController addCustomerInfo]:无法识别的选择器发送到实例 0x6c662b0 2012-08-06 04:16:22.202 TableView[5698:f803] *由于未捕获而终止应用程序异常“NSInvalidArgumentException”,原因:“-[RootViewController addCustomerInfo]:无法识别的选择器发送到实例 0x6c662b0”