iOS 에서 UIAlertView 3 초 후 사라 지 는 두 가지 방법
2472 단어 iosUIAlertView3 초 후사라지다
코드
- (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 초 후 사라 지 는 두 가지 실현 방법 입 니 다.여러분 께 도움 이 되 셨 으 면 합 니 다.궁금 한 점 이 있 으 시 면 댓 글로 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Swift의 패스트 패스Objective-C를 대체하기 위해 만들어졌지만 Xcode는 Objective-C 런타임 라이브러리를 사용하기 때문에 Swift와 함께 C, C++ 및 Objective-C를 컴파일할 수 있습니다. Xcode는 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.