最近做项目的时候,遇到一个问题,就是UIAlterView 设置了标题,但是标题一直显示不出来,但是单独出来自己写个demo,进行测试,又没问题,找了挺久的终于找到原因,因此这边记录一下,方便以后查看,也希望能帮助有遇到此问题的朋友。
这个问题是由于在UIViewController类别里面重写了系统的- (void)setTitle:(NSString)title方法导致的。*
一.UIAlertView显示不出标题
#import"ViewController.h"
@implementationUIViewController (Extention)
- (void)setTitle:(NSString*)title{
}
@end
@interfaceViewController()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIAlertView*alterView = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"大家 好!"delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alterViewshow];
self.view.backgroundColor= [UIColorwhiteColor];
}
@end
程序运行效果:
![](https://img.haomeiwen.com/i2252551/6b86382227f8d804.png)
二.注释掉-(void)setTitle:(NSString *)title,标题显示出来
#import"ViewController.h"
@implementationUIViewController (Extention)
//- (void)setTitle:(NSString *)title{
//
//}
@end
@interfaceViewController()
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
UIAlertView*alterView = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"大家好!"delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alterViewshow];
self.view.backgroundColor= [UIColorwhiteColor];
}
@end
程序运行效果:
![](https://img.haomeiwen.com/i2252551/5dfe79efd56ded37.png)
三.最后:
送上一直自己挺喜欢的图片:
![](https://img.haomeiwen.com/i2252551/6d55cf4fe84292f1.jpg)
至于具体原因,我百度了下也没有官方说法,在这里就不误导大家,大家可以去了解下,然后跟我说下,大家相互进步。gitHub链接地址大家有兴趣可以看一下,如果觉得不错,麻烦给个喜欢或star,如果有问题请及时反馈,谢谢!
网友评论