IBAction推送视图控制错误 - "expected expression"



嘿,伙计们,很抱歉我环顾四周,但这里预期的表达式错误论坛都与我无关。我正在制作我的第一个应用程序,我所学到的一切都无法帮助我解决这个错误。我看了又看,只在复杂的应用程序中发现了错误,而我的错误很基本。这是:这是更新的代码!!!!!

- (IBAction)StartButton:(id)sender;  <--- "Expected Expression"     
{        
   PrimaryViewController *controller = [[PrimaryViewController alloc] 
         initWithNibName:@"PrimaryViewController" bundle:nil];
   [self.navigationController pushViewController: controller animated:YES];  
}  

阅读这篇文章-这是更新后的代码,错误显示在"预期表达式"的第一行,谢谢!((((更新::它是xibs的,StartViewController是它自己的类。)))请帮忙!关于-(IBAction)。。。行,上面写着预期的表达。当您按下开始按钮IBAction时,我正试图将视图控制器从主菜单推到开始屏幕。它也链接到文件菜单。谢谢

您需要创建一个StartViewController的实例并推送它。试图推动阶级本身是没有意义的。

类似于:

StartViewController *controller = [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
[self.navigationController pushViewController: controller animated:YES];

(假设这是.xib文件的正确名称,并且您的导航堆栈上还没有StartViewController的实例。)

错误可能是因为您正在其他类中输入IBAction方法。。确保它是在所有其他方法之后输入的。。就在@end之前(毕竟)

最新更新