<h1>[置頂] 表格的性能優(yōu)化</h1>1>行高一定要緩存;
2>不要動態(tài)創(chuàng)建子視圖 : a)所有的子視圖都預(yù)先創(chuàng)建; b)如果不需要顯示可以設(shè)置 hidden
;
3>所有的子視圖都應(yīng)該添加到 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.當(dāng)一個界面導(dǎo)航條隱藏時,處理細節(jié)
4.給info.plist添加權(quán)限
5.獲取一個像素的高度
6.函數(shù)的執(zhí)行性能
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修改系統(tǒng)的某一個屬性的類型 (以cell中的imageView為例)
9.性能調(diào)試
10.設(shè)置
IQKeyboardManager
某一個界面不顯示
可以解決聊天界面導(dǎo)航條上移問題,應(yīng)該可以使用與隱藏鍵盤上的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 轉(zhuǎn)換成數(shù)組
NSString *content = message.payloadString;
NSData *data =[content dataUsingEncoding:NSUTF8StringEncoding];
NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
12.把字典轉(zhuǎn)成NSData
NSDictionary *dic = @{};
NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil];
13.json格式字符串轉(zhuǎn)字典
- (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
對應(yīng)的值是否為空
[dicdata[@"from"] isEqual:[NSNull null]];
15.把NSData轉(zhuǎn)成NSString
NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- 系統(tǒng)導(dǎo)航欄,返回按鈕, 隱藏 "返回" 文字
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] init];
barItem.title = @"";
self.navigationItem.backBarButtonItem = barItem;
同時再設(shè)置顏色,就可以達到設(shè)計師的要求
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)}];