2011-09-02 67 views
0

我有以下的代码,但不能编译它,因为我有一个“类型名称需要说明符或限定词”错误”的(个体经营)。“类型名称需要说明符或限定词”错误

如何解决这个问题?我已经与原来的代码相比,它并没有差异,所以我不知道发生了什么事情。

#import "CurrentTimeViewController.h" 


@implementation CurrentTimeViewController 

{ 
    // Call the superclass's designated initializer 
    self = [super initWithNibName:@"CurrentTimeViewController" 
         bundle:nil]; 

    if (self) { 
     // Get the tab bar item 
     UITabBarItem *tbi = [self tabBarItem]; 

     // Give it a label 
     [tbi setTitle:@"Time"]; 
    } 
    return self; 
} 

下面是从镜像文件HynososViewController.h的代码,这是我剪切,粘贴和修改:

#import "HypnososViewController.h" 


@implementation HypnososViewController 

- (id) init 
{ 
    // Call the superclass's designated initializer 
    self = [super initWithNibName:nil 
         bundle:nil]; 

    if (self) { 
     // Get the tab bar item 
     UITabBarItem *tbi = [self tabBarItem]; 

     // Give it a label 
     [tbi setTitle:@"Hypnosis"]; 
    } 
    return self; 
} 

- (id) initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle 
{ 
    // Disregard parameters - nib name is an implementation detail 
    return [self init]; 
} 

// This method gets called automatically when the view is created 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSLog(@"Loaded the view for HypnosisViewController"); 

    // Set the background color of the view so we can see it 
    [[self view] setBackgroundColor:[UIColor orangeColor]]; 
} 
@end 

这里是CurrentTimeViewController.h的完整代码:

#import "CurrentTimeViewController.h" 


@implementation CurrentTimeViewController 

{ 
    // Call the superclass's designated initializer 
    self = [super initWithNibName:@"CurrentTimeViewController" 
         bundle:nil]; 

    if (self) { 
     // Get the tab bar item 
     UITabBarItem *tbi = [self tabBarItem]; 

     // Give it a label 
     [tbi setTitle:@"Time"]; 
    } 
    return self; 
} 

- (id) initWithNibName:(NSString *)nibName bundle:(NSBundle *)Bundle 
{ 
    // Disregard parameters - nib name is an implementation detail 
    return [self init]; 
} 

// This method gets called automatically when the view is created 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSLog(@"Loaded the view for CurrentTimeViewController"); 

    // Set the background color of the view so we can see it 
    [[self view] setBackgroundColor:[UIColor greenColor]]; 
} 



@end 
+0

真的在这些代码行? – 2011-09-02 17:45:30

+0

这是什么在xCode 4突出显示。有趣的是,在另一个视图控制器,除了笔尖和颜色的名称完全相同,没有这样的问题。 – pdenlinger

回答

0

是上面的正是你所想要编译什么剪切和粘贴代码?如果是这样,我认为你缺少的东西非常重要,这将使该代码块的方法实现:

-(id)init // This, or something like it, is missing??? 
{ 
    ... 
} 

检查你的代码,在这里,并在您的项目。 :-)

+0

我已经添加了上述两个文件的代码。谢谢。 – pdenlinger

+0

太好了。这是从你最初粘贴的内容中缺少的:' - (id)init'。这很可能是你正在编译的代码所缺少的,这会产生你所看到的错误......我敢打赌。 –

+0

这个技巧。谢谢。 – pdenlinger

相关问题