2011-01-28 7 views
0

다음 코드를 사용하여 경고 상자를 표시합니다.iPhone SDK : 어떻게 경고 상자를 숨길 수 있습니까?

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 

전화가 방향을 바꿀 때 경고 상자를 다시 숨기는 방법을 알려주시겠습니까?

+0

에서 [마크 다운 편집 도움말]을 참조하십시오에게 (HTTP를 추가해야합니다 : // 유래 .com/editing-help) 페이지에서 질문 서식을 지정하십시오. 가장 중요한 것은 코드 앞에 4 칸을 써야하므로 코드처럼 형식이 지정됩니다 (또는 선택하고'{} '버튼을 누름). –

답변

3

먼저 인터페이스에 경고에 대한 참조를 저장해야합니다. 당신이 경고를 생성 할 때

@interface MyViewController : UIViewController { 
    UIAlertView *alert; 
} 
@property (nonatomic, retain) IBOutlet UIAlertView *alert; 

당신은

self.alert = [[[UIAlertView alloc] initWithTitle:@"Info" message:@"My Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; 
[alert show]; 

사용하고 당신은 다른 방법 didRotateFromInterfaceOrientation:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES]; 
    self.alert = nil; 
} 
관련 문제