5

UIToolBar で完了ボタンがクリックされたときに、「TableViewController」の .nib を表示したいと考えています。ただし、以下では、クリックして新しいビューを表示することはできません。これを修正するにはどうすればよいですか?どこが間違っていたのか、何を置き換える必要があるのか​​、その理由を教えてください。

//Here's the selector in my overlay. 
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)];

//Here's how I made my action. Btw, the uitoolbar has no nib, it's an overlay on the
//(camera mode).

-(void)doneButtonPressed {
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:@"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
}


//Yet nothing happens when I click on my done button on my overlay. And I've made sure
//   i've imported .h frameworks correctly too.

UItoolbar オーバーレイ上にある barbuttonitem から nib を表示するとします。どのようにしますか?

適切に機能させるには、[barButtonItem addTarget:self action:@selector(doneButtonPressed) forControlEvents:UIControlEventTouchUpInside]; を追加する必要があると言われました。.

しかし、それを追加すると、次のようになります。

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone addTarget:self action:@selector(doneButtonPressed)
forControlEvents:UIControlEventTouchUpInside];

その結果、「インスタンスメソッド' - initWithBarButtonSystemItem:target:action:forControlEvents:' not found (return type defaults to 'id')」というエラーが表示されます

正しい添加剤だけを示すのではなく、ここに書いたコードに加えて解決策を示してください。

4

3 に答える 3

5

XCode 4 を使用している場合は、Ctrl キーを押しながらBarButtonItem, を .h ファイルにドラッグするだけで、そこから IB アクションを自動的に作成できます。

于 2012-08-01T18:41:30.183 に答える
1

AUIBarButtonItemはデフォルトに従い、設定UIControlEventTouchUpInsideすることはできません。Xcode はそれを割り当てる方法を自動提案する必要がありますが、正しいコードは次のとおりです。

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)];

ないことに注意してくださいforControlEvents:

于 2012-08-01T19:09:21.550 に答える
1

これらの変更を試してください:

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];

-(void)doneButtonPressed:(id)sender
{
}

ターゲットには、アクションを開始したオブジェクト (つまり、UIBarButtonItem 自体) が渡されます。

次に、doneButtonPressed 関数にブレークポイントを設定します。たとえば、tableView が nil に設定されている場合、何も起こらないことがわかります。つまり、このビュー コントローラーのインスタンス化に問題がある可能性があります。

于 2012-08-01T19:58:51.077 に答える