在消息发送表达式的开头缺少'['

时间:2014-03-29 22:21:12

标签: 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

3 个答案:

答案 0 :(得分:1)

那一行应该是:

ViewController *view = [[ViewController alloc] initWithNibName:nil bundle:nil];  //My error is on this line, it says Missing '[' at start of message send expression

您需要添加" ="。

答案 1 :(得分:1)

代码缺少一些有用的东西,比如=

因此[..]


代码实际上被解析为变量数组声明,考虑

X* x[..];

其中..

[ViewController alloc] initWithNibName:nil bundle:nil

导致"缺失' ['在消息的开始发送表达式",就好像该代码本身出现在语句中一样。添加另一对[]'将修复"那,并且实际上声明了variable-length array。但是,你绝对不想在这里使用VLA ..只需添加赋值运算符。

答案 2 :(得分:1)

错误的行应该是:

ViewController *view = [[ViewController alloc] initWithNibName:nil bundle:nil];  

注意'='字符