“类型名称需要说明符或限定符”错误

时间:2011-09-02 17:39:46

标签: ios4

我有以下代码,但无法编译它,因为我有一个“类型名称需要说明符或限定符”错误“for(self)。

如何解决此错误?我把它与原始代码进行了比较,没有差异,所以我不知道发生了什么。

#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

1 个答案:

答案 0 :(得分:0)

上面的代码是否完全是您正在尝试编译的剪切和粘贴?如果是这样,我认为你遗漏了一些非常重要的东西,会使代码阻塞方法实现:

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

检查您的代码,此处以及项目中的代码。 : - )