四十、AFNetworking 传送 form-data

将JSON的数据,转化为NSData, 放入Request的body中。 发送到服务器就是form-data格式。

四十一、非空判断注意

BOOL hasBccCode = YES;

if ( nil == bccCodeStr

|| [bccCodeStr isKindOfClass:[NSNull class]]

|| [bccCodeStr isEqualToString:@""])

{

hasBccCode = NO;

}

如果进行非空判断和类型判断时,需要新进行类型判断,再进行非空判断,不然会crash。

四十二、iOS 8.4 UIAlertView 键盘显示问题

可以在调用UIAlertView 之前进行键盘是否已经隐藏的判断。

@property (nonatomic, assign) BOOL hasShowdKeyboard;

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(showKeyboard)

name:UIKeyboardWillShowNotification

object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(dismissKeyboard)

name:UIKeyboardDidHideNotification

object:nil];

- (void)showKeyboard

{

self.hasShowdKeyboard = YES;

}

- (void)dismissKeyboard

{

self.hasShowdKeyboard = NO;

}

while ( self.hasShowdKeyboard )

{

[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];

}

UIAlertView* alerview = [[UIAlertView alloc] initWithTitle:@"" message:@"取消修改?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: @"确定", nil];

[alerview show];

四十三、模拟器中文输入法设置

模拟器默认的配置种没有“小地球”,只能输入英文。加入中文方法如下:

选择Settings—>General–>Keyboard–>International KeyBoards–>Add New Keyboard–>Chinese Simplified(PinYin) 即我们一般用的简体中文拼音输入法,配置好后,再输入文字时,点击弹出键盘上的“小地球”就可以输入中文了。

如果不行,可以长按“小地球”选择中文。

四十四、iPhone number pad

phone 的键盘类型:

  1. number pad 只能输入数字,不能切换到其他输入

  2. phone pad 类型: 拨打电话的时候使用,可以输入数字和 + * #

四十五、UIView 自带动画翻转界面

- (IBAction)changeImages:(id)sender

{

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:1.0];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:_parentView cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:_parentView cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_parentView cache:YES];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_parentView cache:YES];

NSInteger purple = [[_parentView subviews] indexOfObject:self.image1];

NSInteger maroon = [[_parentView subviews] indexOfObject:self.image2];

[_parentView exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];

[UIView setAnimationDelegate:self];

[UIView commitAnimations];

}

四十六、KVO 监听其他类的变量

[[HXSLocationManager sharedManager] addObserver:self

forKeyPath:@"currentBoxEntry.boxCodeStr"

options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionOld context:nil];

在实现的类self中,进行[HXSLocationManager sharedManager]类中的变量@“currentBoxEntry.boxCodeStr” 监听。

四十七、ios9 crash animateWithDuration

在iOS9 中,如果进行animateWithDuration 时,view被release 那么会引起crash。

[UIView animateWithDuration:0.25f animations:^{

self.frame = selfFrame;

} completion:^(BOOL finished) {

if (finished) {

[super removeFromSuperview];

}

}];

会crash。

[UIView animateWithDuration:0.25f

delay:0

usingSpringWithDamping:1.0

initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveLinear

animations:^{

self.frame = selfFrame;

} completion:^(BOOL finished) {

[super removeFromSuperview];

}];

不会Crash。

四十八、对NSString进行URL编码转换

iPTV项目中在删除影片时,URL中需传送用户名与影片ID两个参数。当用户名中带中文字符时,删除失败。

之前测试时,手机号绑定的用户名是英文或数字。换了手机号测试时才发现这个问题。

对于URL中有中文字符的情况,需对URL进行编码转换。

urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

四十九、Xcode iOS加载图片只能用PNG

虽然在Xcode可以看到jpg的图片,但是在加载的时候会失败。

错误为 Could not load the “ReversalImage1” image referenced from a nib in the bun

必须使用PNG的图片。


如果需要使用JPG 需要添加后缀

[UIImage imageNamed:@"myImage.jpg"];

五十、保存全屏为image

CGSize imageSize = [[UIScreen mainScreen] bounds].size;

UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);

CGContextRef context = UIGraphicsGetCurrentContext();

for (UIWindow * window in [[UIApplication sharedApplication] windows]) {

if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {

CGContextSaveGState(context);

CGContextTranslateCTM(context, [window center].x, [window center].y);

CGContextConcatCTM(context, [window transform]);

CGContextTranslateCTM(context, -[window bounds].size.width*[[window layer] anchorPoint].x, -[window bounds].size.height*[[window layer] anchorPoint].y);

[[window layer] renderInContext:context];

CGContextRestoreGState(context);

}

}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

五十一、判断定位状态 locationServicesEnabled

这个[CLLocationManager locationServicesEnabled]检测的是整个iOS系统的位置服务开关,无法检测当前应用是否被关闭。通过

CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {

[self locationManager:self.locationManager didUpdateLocations:nil];

} else { // the user has closed this function

[self.locationManager startUpdatingLocation];

}

CLAuthorizationStatus来判断是否可以访问GPS

五十二、微信分享的时候注意大小

text 的大小必须 大于0 小于 10k

image 必须 小于 64k

url 必须 大于 0k

五十三、图片缓存的清空

一般使用SDWebImage 进行图片的显示和缓存,一般缓存的内容比较多了就需要进行清空缓存

清除SDWebImage的内存和硬盘时,可以同时清除session 和 cookie的缓存。

// 清理内存

[[SDImageCache sharedImageCache] clearMemory];

// 清理webview 缓存

NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

for (NSHTTPCookie *cookie in [storage cookies]) {

[storage deleteCookie:cookie];

}

NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];

[config.URLCache removeAllCachedResponses];

[[NSURLCache sharedURLCache] removeAllCachedResponses];

// 清理硬盘

[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{

[MBProgressHUD hideAllHUDsForView:self.view animated:YES];

[self.tableView reloadData];

}];

五十四、TableView Header View 跟随Tableview 滚动

当tableview的类型为 plain的时候,header View 就会停留在最上面。

当类型为 group的时候,header view 就会跟随tableview 一起滚动了。

五十五、TabBar的title 设置

在xib 或 storyboard 中可以进行tabBar的设置

其中badge 是自带的在图标上添加一个角标。

1. self.navigationItem.title 设置navigation的title 需要用这个进行设置。

2. self.title 在tab bar的主VC 中,进行设置self.title 会导致navigation 的title 和 tab bar的title一起被修改。

五十六、UITabBar,移除顶部的阴影

添加这两行代码:

[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];

顶部的阴影是在UIWindow上的,所以不能简单的设置就去除。

五十七、当一行中,多个UIKit 都是动态的宽度设置

设置horizontal的值,表示出现内容很长的时候,优先压缩这个UIKit。

五十八、JSON的“” 转换为nil

使用AFNetworking 时, 使用

AFJSONResponseSerializer *response = [[AFJSONResponseSerializer alloc] init];

response.removesKeysWithNullValues = YES;

_sharedClient.responseSerializer = response;

这个参数 removesKeysWithNullValues 可以将null的值删除,那么就Value为nil了

END

写吐了,那么长应该是没人会看完的,看完了算你狠。

iOS开发经验总结(下)的更多相关文章

  1. 移动web在ios和android下点击元素出现阴影问题

     移动web开发经验总结 1.-webkit-tap-highlight-color:rgba(255,255,255,0)可以同时屏蔽ios和android下点击元素时出现的阴影.备注:transp ...

  2. iOS 开发经验总结

    iOS 开发经验总结http://www.cocoachina.com/ios/20170216/18699.html 1.cocoa pods 常用的framework 1 2 3 4 5 6 7 ...

  3. IOS客户端UIwebview下web页面闪屏问题

    基于ios客户端uiwebview下的web页面,在其内容高度大于视窗高度时,如果点击超过视窗下文档的底部按钮,收缩内容高度,会发生闪屏问题. 外因是由文档的高度大于视窗的高度所致,本质原因未知. 解 ...

  4. iOS开发经验总结——基础工程

    iOS开发经验总结--依赖库 这篇博客,我想说一下开发中经常遇到的一个问题,虚拟个场景描述一下的话,应该是这样的. 项目经理:今天我们正式开始一个新项目,iOSer你负责把苹果端的APP完成,有没有问 ...

  5. char的定义在iOS和Android下是不同的

    char is different in iOS and Android!跨平台开发时很容易忽略的非常坑爹的一个区别. 我的需求是实现一个算法,这个算法在iOS和Android下需要保持一致的结果,很 ...

  6. iosselect:一个js picker项目,在H5中实现IOS的select下拉框效果

    具体文档和demo可以访问github:https://github.com/zhoushengmufc/iosselect 移动端浏览器对于select的展示样式是不一致的,ios下是类似原生的pi ...

  7. 微信下输入法在IOS和安卓下的诡异

    1.验证window.innerHeight 系统版本 iOS9.1.1 安卓4.4.4 没有输入法的情况下 504 567 有输入法的情况下 208 273 看来两者的window.innerHei ...

  8. iOS开发MAC下配置svn

    版本控制对于团队合作显得尤为重要,那么如何在iOS开发中进行版本控制呢?在今天的博客中将会介绍如何在MAC下配置SVN服务器,如何导入我们的工程,如何在Xcode中进行工程的checkOut和Comm ...

  9. iOS ARC环境下dealloc的使用

    众所周知,iOS开发的时候,使用ARC的话,dealloc函数是不需要实现的,写了反而会出错. 但有些特殊的情况,dealloc函数还是需要的. 比如,在画面关闭的时候,需要把ViewControll ...

随机推荐

  1. API:System V & POSI

    http://blog.sina.com.cn/s/blog_5b1572e30100gulz.html

  2. 实验一DOS报告

    实验一.DOS命令解释程序的编写实验 13物联网  李名贵  201306104123 一.        实验目的 (1)认识DOS: (2)掌握命令解释程序的原理: (3)掌握简单的DOS调用方法 ...

  3. 【转】can't find referenced method 'android.app.RemoteInput[] getRemoteInputs()' in class android.app.Notification$Action

    原文网址:http://stackoverflow.com/questions/25508735/cant-find-referenced-method-android-app-remoteinput ...

  4. js制作圆角按钮(兼容谷歌,ie7,ie8)

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. 用PowerShell批量部署wsp包

    转:http://www.xuebuyuan.com/168337.html 提供wsp部署的参数: $wsppath:wsp文件所在的路径,如"c:\" $wspnames:路径 ...

  6. spring3 mvc使用注解方式时,不能扫描jar包里面的类

    使用eclipse export工具时选中Add directory entries可以解决.

  7. 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程05:技能读表》

    5.技能读表 技能读表概述: 技能读表,作为实现技能系统更为快捷的一种方式,被广泛应用到游戏开发中.技能配表,作为桥梁连接着游戏策划者和开发者在技能实现上的关系.在游戏技能开发中,开发者只需要根据策划 ...

  8. linux统计文件夹某一些文件的大小总和

    du -m smallgame_2006* | awk '{sum += $1}; END{print sum}' -m代表单位是MB, awk命令需要'',且命令需换行

  9. HDOJ-ACM1021(JAVA)

    题意: 斐波拉契数列的另外一个变型,如果F(n)能被3整除,则输出yes,否则输出no.(n<1000000) 解题思路: 看到(n<1000000)这个条件,有点感觉递归量有点大,因此要 ...

  10. 数据中心基础设施自动化运维之puppet专项

    http://forge.puppetlabs.com/treydock/yum_cron  [puppet功能扩展forge] http://docs.puppetlabs.com/referenc ...