0

ナビゲーションバーの上部に情報ボタンを追加しようとしています。情報ボタンは、ユーザーを情報ビューに誘導します。次のコードはiPhoneのデフォルト情報ボタンをナビゲーションバーに追加します。これは、RootViewController.mのviewDidLoad関数の内部に配置されます。ナビゲーションバーに情報アイコンを追加し、showInfoViewメソッドを実装する方法は?

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メソッドを実装するのに問題がある人はいませんでした。

答えて

-1

使用このコード:

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.rightBarButtonItem = infoButton; 

showInfoView:方法は細かいnibファイル名は "InfoView.xib" ではない "InfoViewController.xib"

+0

は、次のエラーがスローされていれば動作するはずです:***終端'UIButton createViewForNavigationItem:]:インスタンスに送信された認識できないセレクタ0x4b51bb0'、理由: 'UIButton createViewForNavigationItem:':未知のセレクタ 'NSInvalidArgumentException' – Richard

関連する問題