objective-c - 消息开始处缺少 '['发送表达式

标签 objective-c syntax-error

我收到此错误消息并匹配了括号,找不到任何错误。您能找到问题所在吗?我真的需要帮助请。我得到的错误是“在消息发送表达式的开头缺少'['”,我已在代码末尾注释了它发生的位置。请帮我。

谢谢。

@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/

相关文章:

objective-c - 我应该释放添加到从文件初始化的字典中的对象吗?

objective-c - 将焦点放在输入字段时停止自动调整 uiwebview web 内容的大小

ios - UIScrollView 中的 UITextView 使用自动布局

mysql - 在 Rails 中创建新对象时出错

c++ - 错误代码Visual Studio错误:c2059 strange syntax error

iphone - 已识别 UITavleViewCell 标签中的点击手势,但也不选择单元格

iphone - PhoneGap/iOS,从 .shouldStartLoadWithRequest() 打开 ChildBrowser?

php 和 mysql 查询 - 无法从 MySQL 返回我需要的变量

ruby - 使用<<时出现语法错误,但使用+ =时则没有

python - Python 中非本地语句的语法错误