2012-02-29 5 views
0

Я пишу простое приложение с несколькими представлениями с одним корневым контроллером и двумя контроллерами представления (синий и желтый). Когда я пытаюсь запустить его в iPhone Simulator, я получаю сообщение об ошибке с помощью свойства @synthesize. Я прокомментировал ошибку на этой строке.Тема 1: EXC_BAD_ACCESS (код = 2, адрес = 0xbf7ffffc)

Можете ли вы сказать мне, что означает ошибка, и как я могу запустить приложение?

спасибо.

#import "SwitchViewController.h" 
#import "BlueViewController.h" 
#import "YellowViewController.h" 

@interface SwitchViewController() 

@end 

@implementation SwitchViewController 
@synthesize yellowViewController; 
@synthesize blueViewController; //Thread 1:EXC_BAD_ACCESS(code=2, address=0xbf7ffffc) 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)loadView 
{ 
    // If you create your views manually, you MUST override this method and use it to create your views. 
    // If you use Interface Builder to create your views, then you must NOT override this method. 
} 

- (void)viewDidLoad 

{ 
    self.blueViewController = [[BlueViewController alloc]initWithNibName:@"BlueView" bundle:nil]; 
    [self.view insertSubview:self.blueViewController.view atIndex:0]; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (IBAction)switchViews:(id)sender 
{ 
    if(self.yellowViewController.view.superview==nil) { 
     if(self.yellowViewController==nil) { 
      self.yellowViewController = 
      [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil]; 
     } 
     [blueViewController.view removeFromSuperview]; 
     [self.view insertSubview:self.yellowViewController.view atIndex:0]; 
    } else { 
     if (self.blueViewController == nil) { 
      self.blueViewController = 
      [[BlueViewController alloc] initWithNibName:@"BlueView" bundle:nil]; 
     } 
    } 

} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc. that aren't in use 
    if (self.blueViewController.view.superview == nil) { 
     self.blueViewController = nil; 
    } else { 
     self.yellowViewController = nil; 
    } 
} 

@end 

ответ

1

Закомментируйте метода loadView в вашем SwitchViewController, BlueViewController и YellowViewController. Пустой шаблон приложения был изменен, чтобы оставить их без комментирования в последних версиях XCode, но в начальной книге разработки iOS, в которой вы работаете, использовалась более старая версия с предварительно записанными методами.

Смежные вопросы