生活随笔
收集整理的這篇文章主要介紹了
IOS9+基础之警报框弹出和操作表弹出
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
IOS9+基礎之警報框彈出和操作表彈出
代碼如下
#import "ViewController.h"@interface ViewController ()
- (IBAction
)rightClick
:(id
)sender
;@end@implementation ViewController
- (IBAction
)clck2
:(id
)sender
{
UIAlertController
*alert
= [UIAlertController alertControllerWithTitle
:@"標題" message
:@"這是一些信息" preferredStyle
:UIAlertControllerStyleAlert
];UIAlertAction
*conform
= [UIAlertAction actionWithTitle
:@"確認" style
:UIAlertActionStyleDefault handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了確認按鈕");}];UIAlertAction
*cancel
= [UIAlertAction actionWithTitle
:@"取消" style
:UIAlertActionStyleCancel handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了取消按鈕");}];
[alert addAction
:conform
];[alert addAction
:cancel
];[self presentViewController
:alert animated
:YES completion
:nil
];}- (IBAction
)leftClick
:(id
)sender
{
UIAlertController
*alert
= [UIAlertController alertControllerWithTitle
:@"標題" message
:@"這是一些信息" preferredStyle
:UIAlertControllerStyleAlert
];UIAlertAction
*conform
= [UIAlertAction actionWithTitle
:@"確認" style
:UIAlertActionStyleDefault handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了確認按鈕");}];UIAlertAction
*cancel
= [UIAlertAction actionWithTitle
:@"取消" style
:UIAlertActionStyleCancel handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了取消按鈕");}];[alert addTextFieldWithConfigurationHandler
:^(UITextField
* _Nonnull textField
) {textField
.placeholder
= @"請填寫您的反饋信息";}];[alert addAction
:conform
];[alert addAction
:cancel
];[self presentViewController
:alert animated
:YES completion
:nil
];}- (void)viewDidLoad
{[super viewDidLoad
];}- (IBAction
)rightClick
:(id
)sender
{UIAlertController
*alertSheet
= [UIAlertController alertControllerWithTitle
:@"標題" message
:@"一些信息" preferredStyle
:UIAlertControllerStyleActionSheet
];UIAlertAction
*action1
= [UIAlertAction actionWithTitle
:@"項目1" style
:UIAlertActionStyleDefault handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了項目1");}];UIAlertAction
*action2
= [UIAlertAction actionWithTitle
:@"項目2" style
:UIAlertActionStyleDefault handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了項目2");}];UIAlertAction
*cancel
= [UIAlertAction actionWithTitle
:@"取消" style
:UIAlertActionStyleCancel handler
:^(UIAlertAction
* _Nonnull action
) {NSLog(@"點擊了取消");}];[alertSheet addAction
:action1
];[alertSheet addAction
:action2
];[alertSheet addAction
:cancel
];[self presentViewController
:alertSheet animated
:YES completion
:nil
];}
@end
總結
以上是生活随笔為你收集整理的IOS9+基础之警报框弹出和操作表弹出的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。