`#大牛的开发经验总结
1.cocoa pods 常用的framework
platform :ios, '7.0'
target 'store' do
pod 'AFNetworking', '~> 3.1.0'
pod 'JSONKit', '~> 1.5pre'
pod 'MBProgressHUD', '~> 0.9.2'
pod 'SDWebImage', '~> 3.7.6'
pod 'SVPullToRefresh', '~> 0.4.1'
pod 'JTObjectMapping', '~> 1.1.2'
pod 'MagicalRecord', '~> 2.3.2'
pod 'GetuiSDK', '~> 1.4.2'
pod 'XTSafeCollection', '~> 1.0.4'
pod 'libWeChatSDK', '~> 1.6.2'
pod 'XMLDictionary', '~> 1.4'
pod 'Masonry', '~> 1.0.0'
pod 'OpenUDID', '~> 1.0.0'
pod 'SAMKeychain', '~> 1.5.0'
pod 'iVersion', '~> 1.11.4'
pod 'iCloudDocumentSync', '~> 7.4.1'
end
2.NSInteger打印以及字符串的转换
NSInteger integer = 1;
NSLog(@"first number: %zd", integer);
NSUInteger uinteger = 1;
NSLog(@"second number: %tu", uinteger);
3.UIScrollView 在iOS7中使用了Autolayout 导致不能滚动
- (void)viewDidLayoutSubviews
{
[_mainScrollView setContentSize:CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT + 10)];//增加10个像素让scrollview可上下滑动
}
4.APP包瘦身
1)删除项目中没有使用的图片。 [查找XCode工程中没被使用的图片资源](http://blog.lessfun.com/blog/2015/09/02/find-unused-resources-in-xcode-project/)
2)删除项目中没有用到的class 和 xib 及storyboard。[分析工程中没有用到class](https://github.com/jcavar/xcfui)
安装 fui 工具
sudo gem install fui -n /usr/local/bin
fui usage: https://github.com/dblock/fui
到工程目录下,执行 fui find 命令,可以找出所有的没有用到的class文件。
3)分析ipa包,找出大于500K的文件或内容 使用
find . -type f -size +500000c | xargs ls -lh
![图形搜索法](http://mmbiz.qpic.cn/mmbiz_png/foPACGrddJ0PiadwJgk0eOAfzIEfMz3kic3EcDLMK6Ric2T8WnKqThdVojuvDnwnqFzhhqJPCgJAyBsLdNibw59R4A/640?wx_fmt=png&wxfrom=5&wx_lazy=1)
5.直接iOS7的连续跳转
- (void)back
{
[self dismissViewControllerAnimated:YES
completion:^{
if(self.loginCanceled) {
self.loginCanceled();
self.loginCanceled = nil;
}
}];
}
其中loginCanceled的实现
[weakSelf.navigationController popViewControllerAnimated:YES];
6.去除Preferred Max 的警告
警告的原因:
xib或storyboard中添加了UILabel的控件
UILabel的number lines 大于1
UILabel的preferred max没有设置值( @property(nonatomic) CGFloat
preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);)
解决方法:
1)如果是Storyboard的,右键点击警告
2)查看警告的详情
3)复制ID的值在搜索框中进行搜索
4)点击搜索到的Label,可以找到label
5)设置preferred width为0,并选中explicit
6)警告解决
如果警告的是Xib,直接点击警告
就会跳转到对应的UILabel控件,设置preferred width为0,并选中explicit。 警告解决。
7.Cocoa pods更新到1.0 不能用了
Errno::ENOTEMPTY - Directory not empty @ dir_s_rmdir - /Users/arthurwang/SVN///*/Pods
[!] Oh no, an error occurred.Search for existing GitHub issues similar to yours:https://github.com/CocoaPods/CocoaPods/search?q=Directory+not+empty+%40+dir_s_rmdir+-+%2FUsers%2Farthurwang%2FSVN%2F59Store%2Fstoreapp-ios%2Fstore%2FPods&type=IssuesIf none exists, create a ticket, with the template displayed above, on:https://github.com/CocoaPods/CocoaPods/issues/newBe sure to first read the contributing guide for details on how to properly submit a ticket:https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
解决方法:
删除项目中的Pods文件夹,再进行pod install的安装
8.interactivepopgesturerecognizer 使用
设置left bar button后,会导致右滑返回的效果失效,查看完美的设置方案。
同时为了获取到右滑返回的事件,可以执行
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(back)];
在ViewController中viewDidAppare中添加,在viewWillDisappear中remove。
9.更新Cocoapods上的代码
1)采用私有的Cocoapods管理代码,需要添加
pod repo add HXSpec git@code.59store.com:ios/HXSpecs.git
将私有的Spec管理Git添加到pod的specs中。为了方便更新私有库。
2)在使用Cocoapods管理代码的时候,如果在GitHut上更新了代码,希望在project中执行pod install 来刷新代码,那么需要删除Pods和Podfile.lock文件
然后在执行pod install 来刷新代码
使用pod update进行repo的更新(更新私有库)
3)多次安装pod install 会出现Build Phase里多个Check Pods Manifest.lock的选项,这些选项可以删除。
采用直接将specs文件放到HXSpecs的管理库中,那么需要执行pod update 进行
Updating local specs repositories
不然会报错
4)删除这个目录下的缓存文件,进行第三方库文件的重新获取
/Users/arthurwang/Library/Caches/CocoaPods/Pods
5)进行两个组件相互依赖的时候,会导致报错:
[!] There is a circular dependency between StoreLocation and StoreBase
10. UICollectionView的数据不够,无法滑动——解决方案
tableView的数据无论多少,它的界面默认都是可以滑动的。
和tableView相比,当collectionView的数据较少不够一个屏幕时,它无法滑动。
解决方案:
_collectionView.alwaysBounceVertical = YES;
设置为总能垂直滑动就OK了。