2013-02-28 10 views
-1

일부 UILabels 및 버튼이 있습니다. 이것은 내 코드입니다.if 문을 사용하여 레이블 텍스트 변경 - obj c

if ([label.text isEqualToString:@"The three blue dots represents GPS towers. Click Go to advance"]) 
    { 
     firstClick = [[UIAlertView alloc] initWithTitle:@"Welcome!" 
               message:@"Blah, blah blah" 
               delegate:self 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
     [firstClick show]; 

     distanceLabel.text = @"Distance to first tower: 50 km"; 
     a = YES; 
    } 

    if (a) 
    { 
     label.text = @"Now you know that the distance to the first tower is 50 km. Click Go to advance"; 
    } 

이 모든 것은 버튼의 동작 방법에 있습니다. 버튼을 누르면 alertview보기가 표시되고 distanceLabel은 텍스트를 변경합니다. 그런 다음 경고의 OK 버튼을 클릭하여 label.text를 변경하고 싶습니다. 인스턴스 부울 시도했지만 그 doesnt 작동합니다. 왜 그 일을하지 않고 대신 무엇을해야합니까 ??

+1

확인 /부리. 이 경우 –

+0

, 중단 점, 단계 및 nil 확인 및 어쨌든 당신이 틀린 얻을합니다. – Ultrakorne

+0

어떻게 nil을 확인합니까? –

답변

0

당신이 경고보기 버튼을 누를 때 발생하는 동작을하고 싶은 경우에, 당신은 프로토콜의 메소드를 구현해야합니다 있는지 레이블이 전무하지 않고 제대로 스토리 보드 내부에 연결되어 있는지 확인하기 위해

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

    NSLog(@"button clicked at index %d", buttonIndex); 
    NSLog(@"about to update a label. this won't work if it's nil... %@", label); 
    label.text = [NSString stringWithFormat:@"user clicked button %d", buttonIndex"]; 
} 
+0

버튼을 alertview에서 클릭하면 어떻게 확인합니까? –

+0

버튼을 클릭 할 때만 호출됩니다. – danh