美文网首页程序员iOS学习笔记移动开发
UIAlertView  标题显示不出来

UIAlertView  标题显示不出来

作者: 林大鹏 | 来源:发表于2016-12-17 15:47 被阅读197次

最近做项目的时候,遇到一个问题,就是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

程序运行效果:


UIAlterView--无标题

二.注释掉-(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

程序运行效果:

UIAlterView--有标题

三.最后:

送上一直自己挺喜欢的图片:

树.jpg

至于具体原因,我百度了下也没有官方说法,在这里就不误导大家,大家可以去了解下,然后跟我说下,大家相互进步。gitHub链接地址大家有兴趣可以看一下,如果觉得不错,麻烦给个喜欢或star,如果有问题请及时反馈,谢谢!

相关文章

网友评论

    本文标题:UIAlertView  标题显示不出来

    本文链接:https://www.haomeiwen.com/subject/ecoomttx.html