【问题标题】:UIAlertView and UIAlertController title does not displayUIAlertView 和 UIAlertController 标题不显示
【发布时间】:2016-09-13 11:16:28
【问题描述】:

我创建了一个警报如下:

// 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];

但是两个效果都是这样的:

我尝试记录警报的标题,但结果为空:

我该如何解决这个问题?

【问题讨论】:

  • 在你尝试修复UIAlertView之前:不要使用它。它在 iOS 8 中已被弃用。
  • 您是否在代码中的某处使用 setTitle ?
  • 转到产品 -> 清理并重试
  • 您的项目缺少外部内容,您的代码看起来很完美我在我的项目中包含了您的alertcontroller 代码,它工作正常。只需尝试通过同时按下shift+command+option+k 清理构建文件夹或使用此link 可能会有所帮助。
  • @vishnuvarthan 我检查了我项目的所有文件,没有 UIAlertView 或 UIAlertController 这样的方法。

标签: ios objective-c uialertview uialertcontroller


【解决方案1】:

他们都在我身边工作。

尝试使用此代码:

#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

【讨论】:

  • 我新建了一个项目(iOS7及以后),代码是可以的,但是在公司的项目中不行。
猜你喜欢
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
相关资源
最近更新 更多