2013-05-12 5 views
0

"계속 게임"버튼을 표시하기 전에 데이터베이스에서 레코드를로드하는 간단한보기 컨트롤러가 있습니다. 레코드가 _company 변수로로드되고 이것이 올바르게 채워 졌는지 확인할 수 있습니다.prepareForSegue 메소드의 인스턴스 변수가 null입니다.

그러나 prepareForSegue가 실행될 때 변수는 null입니다.

_company 변수가 업데이트되고 prepare ... 메소드에서 사용할 수있는 것과 같은 시간에 문자열 인스턴스를 만들려고 시도한 것처럼 매우 이상합니다.

// StartScreenViewController.h 

@interface StartScreenViewController : UIViewController 

@property (weak, nonatomic) IBOutlet UIButton *continueGameButton; 
@property (weak, nonatomic) Company *company; 
@property (weak, nonatomic) NSString *name; 

- (void)setupGameButtons; 
- (void) getSavedGame; 

@end 


// StartScreenViewController.m 

@implementation StartScreenViewController 

@synthesize continueGameButton = _continueGameButton; 
@synthesize company = _company; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self setupGameButtons]; 
     // Do any additional setup after loading the view. 
} 

- (void)viewDidUnload 
{ 
// self.company = nil; 
    [self setContinueGameButton:nil]; 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (void)setupGameButtons { 
    [self getSavedGame]; 
    if (_company == nil) { 
     _continueGameButton.hidden = YES; 
    } 
} 

- (void)getSavedGame { 
    NSError *error; 
    NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:[Company entityName]]; 
    [fetchRequest setPropertiesToFetch:[NSArray arrayWithObjects:@"name", nil]]; 
    [fetchRequest setFetchLimit:30]; 
    [fetchRequest setFetchBatchSize:30]; 
    NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]; 
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortByName]]; 
    NSArray *results = [[[DomainDataModel sharedDataModel] mainContext] executeFetchRequest:fetchRequest error:&error];  
    _company = [results objectAtIndex:0]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    NSLog(@"company name:: %@", [_company name]); 
// [self getSavedGame]; 
    if ([@"continue_game" isEqualToString:[segue identifier]]) { 
     DashboardViewController *controller = (DashboardViewController *)segue.destinationViewController; 
     controller.company = _company; 

    } 
} 

@end 

완전하게 엉망이되어서 도움이 되었으면합니다.

답변

1

약한 속성으로 선언 된 이유는 무엇입니까? 누가이 부동산을 소유하고 있습니까? 이 선언을 강하게 변경하면 트릭을해야한다는 느낌이 들었습니다.

@property (weak, nonatomic) IBOutlet UIButton *continueGameButton; 
@property (strong, nonatomic) Company *company; 
@property (strong, nonatomic) NSString *name; 
+0

덕분에 - 나는이 다른 유형 : – Ger

+0

나는 그것을 볼 수있는 방법에 대해 좀 더 배울 필요가있다처럼 보인다 - 당신이 그 차이를 모른다면 당신은 다른 작업을 중지하고 객관적인 C를 배워야한다. 기술을 존중 해주세요. – Stavash

+3

나는 접근 방식을 배우는 것을 선호합니다. 과장된 것을 존중하고 싶지는 않습니다.) – Ger

관련 문제