成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

iOS中UIAlertView3秒后消失的兩種實現(xiàn)方法

一,效果圖。

創(chuàng)新互聯(lián)主營巢湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機APP定制開發(fā),巢湖h5重慶小程序開發(fā)搭建,巢湖網(wǎng)站營銷推廣歡迎巢湖等地區(qū)企業(yè)咨詢

iOS中UIAlertView3秒后消失的兩種實現(xiàn)方法

二,代碼。

- (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)結(jié)合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:@"\nMessage 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:afterDelay:方法

- (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];
}

總結(jié)

以上所述是小編給大家介紹的iOS中UIAlertView3秒后消失的兩種實現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!

文章題目:iOS中UIAlertView3秒后消失的兩種實現(xiàn)方法
本文鏈接:http://jinyejixie.com/article10/gdghgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、全網(wǎng)營銷推廣企業(yè)建站、ChatGPT、品牌網(wǎng)站制作、移動網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司