iOS UIAlertView显示不出标题,及重写系统方法
2017-01-22 11:28
447 查看
最近做项目的时候,遇到一个问题,就是UIAlterView
设置了标题,但是标题一直显示不出来,但是单独出来自己写个demo,进行测试,又没问题,找了挺久的终于找到原因:
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"标题" message:@"这个是UIAlertView的默认样式"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"好的", nil];
[alertview show];
新建工程后创建AlertView发现title可以正常显示,但是在我们的工程中就是无法显示title,感觉很奇怪;找了很久后发现,我们工程中给ViewController的系统setTitle方法重写了,由于重写ViewController的setTitle方法,导致AlertView 的setTitle无法调用,所以暂时我的解决方式是将Settitle方法先不重写,就可以简单粗暴的解决这个问题;
一下附上我们的重写系统setTitle方法,大家可以互相学习
@implementation UIViewController (Title)
+ (void)load
{
static
dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// [self exchangeSystemMethod:@selector(setTitle:) customMethod:@selector(custom_setTitle:)];
});
}
+ (void)exchangeSystemMethod:(SEL)systemMethod customMethod:(SEL)customMethod
{
Class class = [self
class];
SEL originalSelector = systemMethod;
SEL swizzledSelector = customMethod;
Method originalMethod =
class_getInstanceMethod(class, originalSelector);
Method swizzledMethod =
class_getInstanceMethod(class, swizzledSelector);
BOOL success =
class_addMethod(class, originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(class, swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (void)custom_setTitle:(NSString *)title
{
self.navigationItem.title = title;
}
设置了标题,但是标题一直显示不出来,但是单独出来自己写个demo,进行测试,又没问题,找了挺久的终于找到原因:
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"标题" message:@"这个是UIAlertView的默认样式"
delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"好的", nil];
[alertview show];
新建工程后创建AlertView发现title可以正常显示,但是在我们的工程中就是无法显示title,感觉很奇怪;找了很久后发现,我们工程中给ViewController的系统setTitle方法重写了,由于重写ViewController的setTitle方法,导致AlertView 的setTitle无法调用,所以暂时我的解决方式是将Settitle方法先不重写,就可以简单粗暴的解决这个问题;
一下附上我们的重写系统setTitle方法,大家可以互相学习
@implementation UIViewController (Title)
+ (void)load
{
static
dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// [self exchangeSystemMethod:@selector(setTitle:) customMethod:@selector(custom_setTitle:)];
});
}
+ (void)exchangeSystemMethod:(SEL)systemMethod customMethod:(SEL)customMethod
{
Class class = [self
class];
SEL originalSelector = systemMethod;
SEL swizzledSelector = customMethod;
Method originalMethod =
class_getInstanceMethod(class, originalSelector);
Method swizzledMethod =
class_getInstanceMethod(class, swizzledSelector);
BOOL success =
class_addMethod(class, originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(class, swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
}
- (void)custom_setTitle:(NSString *)title
{
self.navigationItem.title = title;
}
相关文章推荐
- UIAlertView中显示进度条 ios iphone xcode
- 解决 通过继承QAbstractTableModel并实现headerData方法给QTableView添加标题时,标题不显示 的问题
- IOS 表视图(UITableVIew)的使用方法(2)名单的分段显示
- 让dede系统 正文标题以拼音显示的方法
- iOS调用系统相册显示英文标题
- ios: webview 中 加载状态显示两种方法
- [Android] 获取WebView的页面标题(Title)-----WebChromeClient.onReceivedTitle()方法的重写
- IOS 表视图(UITableVIew)的使用方法(3)名单的索引显示
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- [Android] 获取WebView的页面标题(Title)-----WebChromeClient.onReceivedTitle()方法的重写
- UIAlertView中显示进度条 ios iphone xcode
- ios开发之webView.scalesPageToFit = YES后 加载页面遇见表格显示很小的解决方法
- iOS - 一个类里面写两个UIAlertView 的方法:
- IOS 警告框 (UIAlertView)的使用方法
- Android中的自定义Adapter(继承自BaseAdapter)——与系统Adapter的调用方法一致——含ViewHolder显示效率的优化
- IOS UITableView 选中一行后,不显示选中颜色的方法
- IOS 7 自定义的UIAlertView不能在iOS7上正常显示
- iOS调用系统相册、相机 显示中文标题
- iOS笔记:查询结果为空,显示无数据的方法(UITableView Display No Data)
- Android中的自定义Adapter(继承自BaseAdapter)——与系统Adapter的调用方法一致——含ViewHolder显示效率的优化(转)