0

私は2つのviewControllerを持っています:

  1. DemoAppViewController
  2. ViewControllerについて

AboutViewControllerを開くはずのDemoAppViewControllerに情報ボタンがあります。

現時点では、実行時エラーが発生していますが、その理由がわかりません..

コードは次のとおりです。

DemoAppViewController .h:

- (IBAction)showInfo;

DemoAppViewController.m:

- (IBAction)showInfo {

    AboutViewController *controller = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];



    //setting style with modalTransition property

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;



    //show on screen

    [self presentViewController:controller animated:YES completion:nil];

}

xCode で AboutViewController オブジェクトを作成するとinitWithNibName、次のコードが AboutViewController.m に追加されます。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

上記はそのままにしておきました。

ランタイムエラー:

[DemoAppViewController showInfo:]: unrecognized selector sent to instance 0x688e450

誰かが私が間違っているところを教えてもらえますか? ありがとう。

4

1 に答える 1

0

このメソッドのセレクターは@selector(showInfo)ではなく@selector(showInfo:)です。プログラムで割り当てる場合は、修正するだけです。IB を使用する場合 -:(id) senderパラメータをメソッドに追加します。

于 2012-09-11T00:20:49.780 に答える