我想显示警报。但是由于 iOS 8 不推荐使用 uialertView,我该怎么做才能显示两种操作系统的警报?
问问题
149 次
1 回答
1
试试这个代码片段在 iOS8 中显示警报视图。这肯定会奏效。
- (IBAction)btn1Clicked:(UIButton *)sender {
// 警报样式
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"ALERT!" 留言:@“你会怎么做?” 首选样式:UIAlertControllerStyleAlert ];
__weak ViewController *wself = self;
// Make choices for the user using alert actions.
**UIAlertAction** *doSomethingAction = [UIAlertAction actionWithTitle:@"I'm doing something" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
__strong ViewController *sself = wself;
sself.alertResponseLabel.text = @"You did something!";
}];
UIAlertAction *doNothingAction = [UIAlertAction actionWithTitle:@"I'm totally ignoring this" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
__strong ViewController *sself = wself;
sself.alertResponseLabel.text = @"OK, just ignore me...";
}];
// Add actions to the controller so they will appear
[**alert addAction:doSomethingAction];
[alert addAction:doNothingAction];**
alert.view.tintColor = [UIColor blackColor];
**[self presentViewController:alert animated:YES completion:nil];** }
于 2014-10-23T06:03:30.873 回答