У меня есть следующий код, но я не могу скомпилировать его, потому что у меня есть «Имя типа требует ошибки спецификатора или спецификатора» для (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