语法 - MRC 下全局变量的 Delegate 陷阱
变更记录
序号
录入时间
录入人
备注
1
2016-01-20
Alfred Jiang
-
方案名称语法 - MRC 下全局变量的 Delegate 陷阱
关键字语法 \ Objective-C \ MRC \ 成员变量 \ Delegate
需求场景
使用全局变量时赋值 delegate 需要注意的地方
参考链接(无)
详细内容在 MRC 代码中,当我们对全局成员变量的 delegate 进行赋值时,一定要记得在 dealloc 中释放该全局变量的同时对其中的 delegate 进行置 nil 操作。
否则会在下面的代码中造成 crash。
1234if (delegate && [delegate respondsToSelector:@selector(anymethod:)]) { [delegate anymethod:nil]; }
原因是 MRC 中 delegate 为 assign 修饰,assign 修饰在 self 置 nil 时该变量并不会置 nil。
所以我们必须在 dealloc 中显式的对 ...
Xcode - iOS 开发崩溃(Crash)调试
变更记录
序号
录入时间
录入人
备注
1
2016-01-21
Alfred Jiang
-
方案名称Xcode - iOS 开发崩溃(Crash)调试
关键字Xcode \ 崩溃 \ 日志 \ Crash \ Log \ dSYM \ Symbolicatecrash \ 调试
需求场景
需要对 .crash 文件进行分析时
参考链接
博客园 - iphone崩溃日志分析工具symbolicatecrash用法
CSDN - iOS通过dSYM文件分析crash
简书 - iOS开发技巧-崩溃调试 - 崩溃调试的使用和技巧(推荐阅读)
GitHub - dSYMTools
CocoaChina - 如何使用symbolicatecrash工具
详细内容####Xcode 6.0 之后版本快速使用:
在终端依次输入以下两条命令
export DEVELOPER_DIR=”/Applications/XCode.app/Contents/Developer”/Applications/Xcode. ...
Xcode - 使用 Instruments 的 Allocations 工具检测内存分配情况
变更记录
序号
录入时间
录入人
备注
1
2016-01-21
Alfred Jiang
-
方案名称Xcode - 使用 Instruments 的 Allocations 工具检测内存分配情况
关键字Xcode \ Instruments \ Allocations \ 内存分配
需求场景
需要对 App 进行内存分配检测优化时
《Instruments 用户指南》
参考链接(见详细内容)
详细内容以下链接可以帮助理解内存陷阱并给出了很好的解决方案参考
使用 Swift 和 Objective-C 执行 iOS 内存管理的 7 个简单技巧
51CTO - iOS内存暴增问题追查与使用陷阱
Apple documentation - Finding Abandoned Memory
CocoaChina - iOS系类教程之用instruments来检验你的app:Instruments Tutorial with Swift: Getting Started 译文
iOS系类教程之用instruments来检验你的app
Ray Wenderlich - I ...
UIImage - 获取 UIImage 大小与压缩 UIImage
变更记录
序号
录入时间
录入人
备注
1
2016-01-22
Alfred Jiang
-
方案名称UIImage - 获取 UIImage 大小与压缩 UIImage
关键字UIImage \ 大小 \ 尺寸 \ 压缩
需求场景
需要对加载的 UIImage 进行压缩时
参考链接
CSDN - UIImage 图片处理:截图,缩放,设定大小,存储
Stack Overflow - iOS get UIImage memory size
详细内容获取 UIImage 大小123456789101112UIImage *testImage = [UIImage imageNamed:@"blue2.png"]; //877KB 600*600像素 NSUInteger s1 = UIImagePNGRepresentation(testImage).length; //992400NSUInteger s2 = UIImageJPEGRepresentation(testImage, 1).length; //923 ...
NSMutableSet - 在 NSMutableSet 中添加自定义对象时怎么保证不重复
变更记录
序号
录入时间
录入人
备注
1
2015-06-09
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
方案名称NSMutableSet - 在 NSMutableSet 中添加自定义对象时怎么保证不重复
关键字NSMutableSet \ hash \ isEqual \ 重复
需求场景
需要将自定义对象添加入 NSMutableSet,需要保证不重复
避免存储自定义重复对象
参考链接
NSHipster - Equality
详细内容通过自定义 hasn 与 isEqual 方法定义相等条件
示例代码如下:
ALFImport.h
1234567891011121314151617181920212223242526272829303132//// ALFImport.h// ALFUMLTool//// Created by Alfred Jiang on 6/8/15.// Copyright (c) 2015 Alfred Jiang. All rights reserved.//#import & ...
字体 - 添加自定义字体
变更记录
序号
录入时间
录入人
备注
1
2015-06-12
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
方案名称字体 - 添加自定义字体
关键字字体 \ 自定义字体 \ 非系统字体
需求场景
需要为 App 提供系统之外的字体时
参考链接
CSDN - ios开发 添加自定义字体
字体下载网站一
详细内容
下载需要的 .ttf 格式字体,并添加入工程
在 .plist 中添加如下字段
1234<key>UIAppFonts</key><array><string>OpenSans-Bold.ttf</string></array>
确保 Project -> Targets -> Build Phases -> Copy Bundle Resources 中字体已加入
在工程中执行下面的代码找到字体对应名称
1234567891011121314NSArray *familyNames = [[NSArray alloc] ...
NSString - 删除 NSString 中特定字符
变更记录
序号
录入时间
录入人
备注
1
2015-08-21
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
方案名称NSString - 删除 NSString 中特定字符
关键字NSString \ 删除 \ 字符串
需求场景
删除 NSString 中的数字、符号,或者修改其中的字符
参考链接
iOS 删除NSString中特定字符
详细内容1234567891011121314+(NSString *) stringDeleteString:(NSString *)str{ NSMutableString *str1 = [NSMutableString stringWithString:str]; for (int i = 0; i < str1.length; i++) { unichar c = [str1 characterAtIndex:i]; NSRange range = NSMakeRange(i, 1); if (c ...
Xib - 通过 Xib 加载自定义 Cell
变更记录
序号
录入时间
录入人
备注
1
2015-08-24
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
2
2016-03-11
Alfred Jiang
-
方案名称Xib - 通过 Xib 加载自定义 Cell
关键字Xib \ UITableViewCell \ 自定义
需求场景
需要实现较为复杂的 cell 布局,通过 xib 方式实现
参考链接
简书 - iOS 自定义Cell-通过XIB方式
详细内容2016-03-11 更新
通过 File -> New -> File… -> iOS -> Source -> Cocoa Touch Class 创建 Cell
在 Class 中输入自定义 Cell 名称(示例:PSWConfigSwitchViewCell);在 Subclass of 中输入父类 UITableViewCell ; 勾选 Also create Xib file 选项 ; 选择平台(iPhone / iPad) 和语言(Objectiv ...
NSString - 筛选出 NSString 中特定字符串
变更记录
序号
录入时间
录入人
备注
1
2015-08-25
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
2
2016-05-09
Alfred Jiang
-
方案名称NSString - 筛选出 NSString 中特定字符串
关键字NSString \ 筛选 \ 字符串
需求场景
需要在一个长串中筛选出特定的字串,比如一句中文中筛选出金额数字
筛选出一个字符串指定字符集合
筛选出字符串中全部字母和数字
参考链接
CocoaChina - 在NSString中找到数字转换成int,方法如下。so cool !
详细内容1234NSString *aStr = @"这是一句测试,里面包含了19.23这个数字";NSCharacterSet* nonDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];NSString *aDigits = [aStr stringByTrimmingCharactersInSet:no ...
UITableView - 滑动加载性能优化总结
变更记录
序号
录入时间
录入人
备注
1
2015-09-08
Alfred Jiang
-
2
2015-12-23
Alfred Jiang
-
方案名称UITableView - 滑动加载性能优化总结
关键字UITableView \ UITableViewCell \ reloadData \ 列表 \ 滑动 \ 卡顿 \ 性能优化
需求场景
实现较为复杂的 UITableViewCell 列表和加载大量数据时
参考链接
CocoaChina - 一次 TableView 性能优化经历
伯乐在线 - iOS应用性能调优的25个建议和技巧
iOS App性能优化
GitHub - UITableView优化技巧
UITableView 滚动流畅性优化
详细内容1. 列表卡顿问题最好真机测试,有条件的尽量选择低版本硬件和系统进行测试;2. 使用 Instruments 的 Time Profiler 工具定位造成卡顿时间消耗的位置;3. 避免 UITableView 的多次刷新( reloadData ),尤其 Xib 加载 UITableView 时避免首 ...