2011-03-21 8 views
1

UILabel 첫로드시 업데이트되지 않지만 이후로드시 올바르게로드됩니다.iPhone UILabel이 처음로드시 업데이트되지 않습니다.

다음은 코드 스 니펫입니다. 다시 말했듯이 첫 번째로드에서만 xib의 라벨에 지정된 내용 (예 : label)이 표시되고 두 번째로 label.text= @"Glass, Paper, Cans, Textiles, Card, Shoes and Books"; 문자열이로드됩니다.

-(IBAction)showDetails:(id)sender{ 
    NSLog(@"Annotation Click"); 
    self.userProfileVC.title=((UIButton*)sender).currentTitle; 
    if([((UIButton*)sender).currentTitle isEqualToString:@"Asda"]) 
     self.userProfileVC.label.text= @"Glass, Paper, Cans, Textiles, Card, Shoes and Books"; 

    [UIView beginAnimations:@"Curl Page Down" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown 
         forView:self.view cache:YES];  

    //Adjust the Subview by butting up to status bar 
    self.userProfileVC.view.frame = CGRectMake(0, 0, 320, 480); 
    //Add userProfileVC as a subview 
    [self.view addSubview:userProfileVC.view]; 
    [UIView commitAnimations]; 
} 

답변

0

나는 당신이 처음에 self.userProfileVC.label에 액세스 할 때 뷰 자체가 아직로드되지 않았기 때문에 label 여전히 nil 믿습니다. 빠른 수정 프로그램은 showDetails 메서드의 시작 부분에 self.userProfileVC.view; 문을 입력하여 먼저 뷰를로드해야합니다.

+0

당신이 내게 단서를 주신 덕분에 나는 방금 처음으로보기를 옮겼습니다! –

0

아마도이 코드는 UIButton을 클릭하면 호출됩니다. 따라서 첫 번째 UI로드에서는 메서드를 호출 할 필요가 없습니다 (버튼을 누르지 않았으므로). viewDidLoad 또는 그와 유사한 기본 텍스트를 설정하는 것이 좋습니다.

의 라인을 따라 뭔가 :

- (void)viewDidLoad { 
    self.userProfileVC.label.text= @"Glass, Paper, Cans, Textiles, Card, Shoes and Books"; 
} 
+0

대? 나는 다른 정보가있는 if 문을 52 개 가지고 있는데, 이것을 어떻게 고쳐야할까요? –

+0

"모든 주석"- 당신이하는 일을 볼 수 없으며 언급하지도 않았기 때문에 무슨 뜻인지 알지 못합니다. 전에 주석. 'isEqualToString : @ "Asda"유형의 항목이 많은 경우에는 NSMutableDictionary (또는 일반 NSDictionary)에 label-> annotation 매핑을 저장하는 것이 좋습니다. 그런 다음 'if'의 큰 부담없이 레이블 텍스트를 통해 주석을 조회 할 수 있습니다. – occulus

0

나는 내 코드의 순서를 변경 한 바보이다. 레이블 앞에보기를 먼저로드한다. DOH!

을 Heres 코드 조각 :

- (IBAction를) showDetails (ID) 보낸 사람 {무슨 위의 라벨에로드하지만 지금은 정보가 모든 주석에 대해 동일했다

//Must load the view before the annotations update the label with the correct label text! 
[UIView beginAnimations:@"Curl Page Down" context:nil]; 
[UIView setAnimationDuration:1]; 

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown 
         forView:self.view cache:YES];  

//Adjust the Subview by butting up to status bar 
self.userProfileVC.view.frame = CGRectMake(0, 0, 320, 480); 
//Add userProfileVC as a subview 
[self.view addSubview:userProfileVC.view]; 
[UIView commitAnimations]; 

NSLog(@"Annotation Click"); 
self.userProfileVC.title=((UIButton*)sender).currentTitle; 
if([((UIButton*)sender).currentTitle isEqualToString:@"Asda"]) 
    self.userProfileVC.label.text= @"Glass, Paper, Cans, Textiles, Card, Shoes and Books"; 
+0

아마도 자신의 글을 게시하기보다는 티아의 대답을 받아 들일 것입니다. 최종 수정 방법에 대한 설명을 원한다면 질문을 편집하고 마지막에 "솔루션 부분"을 포함 할 수 있습니다. – Kalle

관련 문제