我收到此错误消息并匹配了括号,找不到任何错误。您能找到问题所在吗?我真的需要帮助请。我得到的错误是“在消息发送表达式的开头缺少'['”,我已在代码末尾注释了它发生的位置。请帮我。
谢谢。
@interface HomeViewOne ()
@end
@implementation HomeViewOne
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)switchScreenHome:(id)sender {
//Code to switch screen from main menu to game
ViewController *view [[ViewController alloc] initWithNibName:nil bundle:nil]; //My error is on this line, it says Missing '[' at start of message send expression
[self presentModalViewController:view animated:YES];
}
@end
最佳答案
该代码缺少有用的内容,例如=
。
因此,[..]
没有以有意义的方式进行解析(即作为赋值中使用的表达式),并导致给定的语法错误。
该代码实际上被解析为变量数组声明,考虑
X* x[..];
..
在哪里[ViewController alloc] initWithNibName:nil bundle:nil
结果是“在消息发送表达式的开头缺少'['”,就像该代码本身出现在语句中一样。添加另一对
[]
将“修复”该错误,并实际上声明一个variable-length array。但是,您绝对不希望在这里使用VLA。只需添加赋值运算符即可。
关于objective-c - 消息开始处缺少 '['发送表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22737673/