0

uibarbutton が応答しません。

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" 
                               style:UIBarButtonItemStylePlain target:nil action:nil];

ユーザーがボタンをタップしても、アクションは発生しません。

4

3 に答える 3

1
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"TITLE"
                                       style:UIBarButtonItemStylePlain
                                       target:self
                                       action:@selector(methodName:)] autorelease]; 
于 2012-08-27T09:27:37.663 に答える
1

そのためには、UIbarbutton に次のコードも使用する必要があります。

UIBarButtonItem *cameraView = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
                               target:self action:@selector(showCam)];

または、次のコードを使用することもできます。

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                        style:UIBarButtonItemStylePlain
                                        target:self
                                                                              action:@selector(showCam)];

それはあなたにも役立つかもしれません。

于 2012-08-27T09:25:22.000 に答える
1

ボタンのコールバックを処理するデリゲートを指定する必要があります ('target' パラメーター、通常は 'self'、および呼び出されるメソッドの名前、'action' パラメーター)。

backButton = [[UIBarButtonItem alloc]
                 initWithTitle:@"Back"
                     style:UIBarButtonItemStylePlain
                     target:self
                     action:@selector(backButtonAction:)];

対象となるクラスにアクションメソッド「backButtonAction」を含めます。したがって、「self」を使用する場合は、次のように、ボタンを追加する同じクラスにメソッドを含めます。

- (void) backButtonAction:(id) sender
{
    NSLog (@"backButtonAction: Sender %p", sender);

    ....
}
于 2012-08-27T09:31:04.790 に答える