国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS中UIAlertView3秒后消失的兩種實現方法

2019-10-21 18:43:16
字體:
來源:轉載
供稿:網友

一,效果圖。

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:@"/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];}

總結

以上所述是小編給大家介紹的iOS中UIAlertView3秒后消失的兩種實現方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VEVB武林網網站的支持!


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阳新县| 玉环县| 敖汉旗| 夹江县| 鄂伦春自治旗| 汉中市| 比如县| 万州区| 马尔康县| 亚东县| 和硕县| 称多县| 交口县| 延庆县| 出国| 贺州市| 莎车县| 建始县| 玉树县| 霞浦县| 南江县| 唐山市| 梁山县| 渭南市| 新河县| 石狮市| 麻城市| 上林县| 洪江市| 霍林郭勒市| 蕉岭县| 获嘉县| 淮北市| 静海县| 绿春县| 台前县| 靖安县| 罗甸县| 华池县| 牙克石市| 郧西县|