我有2个viewControllers:
我在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
有人能告诉我哪里出错了吗? 感谢。
答案 0 :(得分:0)
此方法的选择器为@selector(showInfo)
,而非@selector(showInfo:)
。如果以编程方式分配它,只需更正它。如果您使用IB - 将:(id) sender
参数添加到方法中。