尝试打开新viewController时发送到实例的无法识别的选择器

时间:2012-09-11 00:15:16

标签: iphone xcode

我有2个viewControllers:

  1. DemoAppViewController
  2. AboutViewController
  3. 我在DemoAppViewController中有一个信息按钮,它应该打开AboutViewController。

    目前我遇到了运行时错误,我似乎无法理解为什么......

    以下是代码:

    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];
    
    }
    

    当我用initWithNibName创建AboutViewController对象时,xCode将以下代码添加到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
    

    有人能告诉我哪里出错了吗? 感谢。

1 个答案:

答案 0 :(得分:0)

此方法的选择器为@selector(showInfo),而非@selector(showInfo:)。如果以编程方式分配它,只需更正它。如果您使用IB - 将:(id) sender参数添加到方法中。