[置顶] 表格的性能优化
1>行高一定要缓存;2>不要动态创建子视图 : a)所有的子视图都预先创建; b)如果不需要显示可以设置
hidden
;3>所有的子视图都应该添加到
contentView
上;4>所有的子视图都必须指定背景颜色;
5>所有的颜色都不要使用
alpha
;6>cell栅格化;
7>异步绘制.
//栅格化
self.layer.shouldRasterize = true;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
//异步绘制
self.layer.drawsAsynchronously = true;
1.在方法中用block传值
2.GCD的使用
3.当一个界面导航条隐藏时,处理细节
4.给info.plist添加权限
5.获取一个像素的高度
6.函数的执行性能
7.model中添加despription 打印出model的详细信息
#import "CAChatModel.h"
@implementation CAChatModel
- (NSString *)description
{
NSArray *keys = @[@"message",@"verb",@"time",@"from"];
return [self dictionaryWithValuesForKeys:keys].description;
}
@end
8.利用kvc修改系统的某一个属性的类型 (以cell中的imageView为例)
9.性能调试
10.设置
IQKeyboardManager
某一个界面不显示
可以解决聊天界面导航条上移问题,应该可以使用与隐藏键盘上的toolbar
[[IQKeyboardManager sharedManager].disabledDistanceHandlingClasses addObject:[self class]];
[[[IQKeyboardManager sharedManager] disabledToolbarClasses] addObject:[self class]];
以前是这样处理的,这样很low
//- (void)viewDidAppear:(BOOL)animated
//{
// [super viewDidAppear:animated];
// [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
//}
//- (void)viewDidDisappear:(BOOL)animated
//{
// [super viewDidDisappear:animated];
// [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
//}
11.把字符串类型的json 转换成数组
NSString *content = message.payloadString;
NSData *data =[content dataUsingEncoding:NSUTF8StringEncoding];
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
12.把字典转成NSData
NSDictionary *dic = @{};
NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
13.json格式字符串转字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
if (jsonString == nil) {
return nil;
}
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *err;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
if(err) {
NSLog(@"json解析失败:%@",err);
return nil;
}
return dic;
}
14.判断字典里面的某个key
对应的值是否为空
[dicdata[@"from"] isEqual:[NSNull null]];
15.把NSData转成NSString
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- 系统导航栏,返回按钮, 隐藏 "返回" 文字
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] init];
barItem.title = @"";
self.navigationItem.backBarButtonItem = barItem;
同时再设置颜色,就可以达到设计师的要求
self.navigationController.navigationBar.barTintColor = MainColor(240, 240, 240);
self.navigationController.navigationBar.tintColor = MainColor(70, 70, 70);
[self.navigationController.navigationBar setTitleTextAttributes: @{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:MainColor(70, 70, 70)}];