2012-10-22 67 views
0

我目前正在研究一個應用程序,其中有兩個主要的故事板; ViewController和MainViewController。獲取編譯器錯誤預期標識符/期望的方法體

我想在我的MainViewController.m中出現Expected IdentifierExpected method body錯誤。

這裏是文件:

// 
// MainView.m 
// Ski Finder Intro 
// 
// Created by Hunter Bryant on 10/20/12. 
// Copyright (c) 2012 Hunter Bryant. All rights reserved. 
// 

#import "MainViewController.h" 

@interface MainViewController() 

@end 

@implementation MainViewController 


- (id)initWithNibName:@"MainViewController" bundle:Nil //Here are both of the errors. 
{ 
    self = [super initWithNibName:@"MainViewController'" bundle:Nil]; 
    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. 
} 

@end 

回答

2

你似乎是混亂的方法聲明(在這種情況下超馳)和在Objective-C實際上發送消息。你的方法應該是這樣的:

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil //No more errors. 

要使用的方法,在信息,請撥打[[MyClass alloc]initWithNibName:@"MainViewController" bundle:nil];

而作爲一個旁註:-init...風味的消息幾乎從未被類本身調用,因爲它沒有什麼意義,如果「適當」實施,會創造一些有趣的保留週期。

+0

與您的旁註相反,初始化器應始終在一個類中鏈接。 –

+0

是的,當然,然而我對這種模式感到沮喪。我更喜歡'-commonInit'(這相當於同樣的事情,但... – CodaFi