1

戻るボタンを押してポップビューするにはどうすればよいですか。以前のView Controllerから以下のコードを渡しました。ありがとう

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
         initWithTitle:@"Back"
         style:UIBarButtonItemStyleBordered
         target:nil action:nil];
4

1 に答える 1

3

戻るボタンを手動で追加する必要はありません。

ただし、View Controller をポップするカスタム ボタンが本当に必要な場合は、カスタム メッセージを作成できます。

-(void)popViewControllerWithAnimation {
  [self.navigationController popViewControllerAnimated:YES];
}
...
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
     initWithTitle:@"Back"
     style:UIBarButtonItemStyleBordered
     target:self action:@selector(popViewControllerWithAnimation)];

または、NSInvocation を作成します。

NSInvocation* invoc = [NSInvocation invocationWithMethodSignature:
      [self.navigationController methodSignatureForSelector:@selector(popViewControllerAnimated:)]];
// watch out for memory management issues: you may need to -retain invoc.
[invoc setTarget:self.navigationController];
[invoc setSelector:@selector(popViewControllerAnimated:)];
BOOL yes = YES;
[invoc setArgument:&yes atIndex:2];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
     initWithTitle:@"Back"
     style:UIBarButtonItemStyleBordered
     target:invoc action:@selector(invoke)];
于 2010-05-16T06:23:11.117 に答える