iOS 에서 UIAlertView 3 초 후 사라 지 는 두 가지 방법

효과 도

코드

- (void)viewDidLoad {
 [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
 UIAlertView* alert = [[UIAlertView alloc]initWithTitle:nil message:@"   3    " delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
 [alert show];
 [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:3.0];
}
- (void)dismissAlert:(UIAlertView*)alert {
 if ( alert.visible ) {
  [alert dismissWithClickedButtonIndex:alert.cancelButtonIndex animated:YES];
 }
}
UIAlertView 가 자동 으로 사라 지 는 두 가지 방법 을 소개 해 드 리 겠 습 니 다.
프로그램 을 작성 하 는 과정 에서 힌트 정 보 를 많이 사용 하기 때문에 자 연 스 럽 게 UIAlertView 컨트롤 을 사용 해 야 한다 고 한다.
그러나 이 알림 의 정 보 는 때때로 알림 만 있 으 면 되 고 조작 하지 않 아 도 된다.그러면 이 알림 상자 가 자동 으로 사라 지면 OK 가 된다.
UIAlertView 팝 업 후 2s 자동 으로 사라 지게 하 는 두 가지 방법:
(1)NSTimer 결합

UIAlertView baseAlert = nil;
- (void) performDismiss: (NSTimer *)timer
{
 [baseAlert dismissWithClickedButtonIndex:0 animated:NO];//important
 [baseAlert release];
 baseAlert = NULL;
}  
- (void) presentSheet
{
 baseAlert = [[UIAlertView alloc] 
        initWithTitle:@"Alert" message:@"
Message Message Message " delegate:self cancelButtonTitle:nil otherButtonTitles: nil]; [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector: @selector(performDismiss:) userInfo:nil repeats:NO]; [baseAlert show]; }
(2)PerformSelector:withObject:after Delay:방법 사용

- (void) dimissAlert:(UIAlertView *)alert
{
 if(alert)
 {
  [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
  [alert release];
 }
}
- (void)showAlert{   
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil 
cancelButtonTitle:nil otherButtonTitles:nil];
 [alert show];
 [self performSelector:@selector(dimissAlert:) withObject:alert afterDelay:2.0];
}
총결산
위 에서 설명 한 것 은 편집장 님 께 서 소개 해 주신 iOS 의 UIAlertView 3 초 후 사라 지 는 두 가지 실현 방법 입 니 다.여러분 께 도움 이 되 셨 으 면 합 니 다.궁금 한 점 이 있 으 시 면 댓 글로 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기