我创建了一个警告如下:
// UIAlertView
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:@"Cancel", nil];
[alertView show];
// or UIAlertController
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:NULL]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];
[self presentViewController:alertController animated:YES completion:NULL];
但两种效果都是这样的:
我尝试记录alert的标题,但结果为null:
我该如何解决这个问题?
答案 0 :(得分:0)
他们两个都在我这边工作。
尝试使用此代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" delegate:nil cancelButtonTitle:@"Confirm" otherButtonTitles:@"Cancel", nil];
[alertView show];
[self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(grHandler)]];
}
-(void)grHandler{
// UIAlertController
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"WARNING" message:@"Are you sure you want to quit ?" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:NULL]];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:NULL]];
[self presentViewController:alertController animated:YES completion:NULL];
}
@end