Ios4 &引用;类型名称需要一个说明符或限定符;错误
我有以下代码,但无法编译它,因为我有一个“类型名称需要一个说明符或限定符”错误(self) 如何修复此错误?我已将其与原始代码进行了比较,没有差异,因此我不知道发生了什么Ios4 &引用;类型名称需要一个说明符或限定符;错误,ios4,Ios4,我有以下代码,但无法编译它,因为我有一个“类型名称需要一个说明符或限定符”错误(self) 如何修复此错误?我已将其与原始代码进行了比较,没有差异,因此我不知道发生了什么 #import "CurrentTimeViewController.h" @implementation CurrentTimeViewController { // Call the superclass's designated initializer self = [super initWithN
#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
上面的代码是您正试图编译的内容的剪切粘贴吗?如果是,我认为您缺少了一些非常重要的东西,这些东西会使代码块成为方法实现:
-(id)init // This, or something like it, is missing???
{
...
}
检查您的代码,在这里,在您的项目中。:-这些代码行中真的有错误吗?这是在xCode 4中突出显示的内容。有趣的是,在另一个视图控制器中,除了笔尖的名称和颜色之外,完全相同,没有这样的问题。太好了。这是您最初粘贴的内容中缺少的:
-(id)init
。您试图编译的代码中可能缺少这一点,这将生成您看到的错误…我敢打赌。