我正在尝试在导航栏顶部添加一个信息按钮。信息按钮将用户引导至信息视图。以下代码将 iPhone 默认信息按钮添加到导航栏。它被放置在 RootViewController.m 的 viewDidLoad 函数中。
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
现在,需要实现 showInfoView 方法,使用如下代码:
- (IBAction)showInfoView:(id)sender {
// Create the root view controller for the navigation controller
// The new view controller configures a Cancel and Done button for the
// navigation bar.
InfoViewController *addController = [[InfoViewController alloc]
initWithNibName:@"InfoView" bundle:nil];
// Configure the RecipeAddViewController. In this case, it reports any
// changes to a custom delegate object.
addController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
// The navigation controller is now owned by the current view controller
// and the root view controller is owned by the navigation controller,
// so both objects should be released to prevent over-retention.
[navigationController release];
[addController release];
}
但是当程序构建并运行时,单击信息按钮会导致程序崩溃。
以前有人遇到过这个问题吗?我进行了广泛的搜索,但没有看到任何机构在实施 showInfoView 方法时遇到了麻烦。