中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

iOS警告對話框(Alerts)

IOS警告對話框的使用

警告對話框用來給用戶提供重要信息。

僅在警告對話框視圖中選擇選項后,才能著手進(jìn)一步使用應(yīng)用程序。

重要的屬性

  • alertViewStyle
  • cancelButtonIndex
  • delegate
  • message
  • numberOfButtons
  • title

重要的方法

- (NSInteger)addButtonWithTitle:(NSString *)title
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
- (void)dismissWithClickedButtonIndex:
  (NSInteger)buttonIndex animated:(BOOL)animated
- (id)initWithTitle:(NSString *)title message:
  (NSString *)message delegate:(id)delegate
  cancelButtonTitle:(NSString *)cancelButtonTitle 
  otherButtonTitles:(NSString*)otherButtonTitles, ...
- (void)show

更新 ViewController.h,如下所示

讓類符合警告對話框視圖的委托協(xié)議,如下所示,在ViewController.h中添加<UIAlertViewDelegate>

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIAlertViewDelegate>{
    
}
@end

添加自定義方法 addAlertView

-(void)addAlertView{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Title" message:@"This is a test alert" delegate:self 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alertView show];
}

執(zhí)行警告對話框視圖的委托方法

#pragma mark - Alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
  (NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            NSLog(@"Cancel button clicked");
            break;
        case 1:
            NSLog(@"OK button clicked");
            break;
        
        default:
            break;
    }
}

在 ViewController.m 中修改 viewDidLoad,如下所示

(void)viewDidLoad
{
   [super viewDidLoad];
   [self addAlertView];
}

輸出

現(xiàn)在當(dāng)我們運行該應(yīng)用程序我們會看到下面的輸出:

alertOutput1

其他擴展