来源:蝴蝶之梦天使

链接:http://www.jianshu.com/p/d333cf6ae4b0

四十、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. iOS开发MAC下配置svn

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

  2. iOS开发--Mac下server搭建

    前言 对于Mac电脑的认识.我一直停留在装B神器的意识上.就在前两天我彻底改变了庸俗的看法,当时忙着写毕业设计.苦于iOS开发没有server, 数据都是从网上抓取或本地plist文件,感觉不够高大上 ...

  3. iOS开发MAC下配置Svn和Git

    如果你对iOS开发中的版本控制还不了解那么你可以先看看这篇(大致看一遍就ok) http://www.cnblogs.com/iCocos/p/4767692.html   关于版本控制使用起来并不难 ...

  4. iOS开发-UIRefreshControl下拉刷新

    下拉刷新一直都是第三库的天下,有的第三库甚至支持上下左右刷新,UIRefreshControl是iOS6之后支持的一个刷新控件,不过由于功能单一,样式不能自定义,因此不能满足大众的需求,用法比较简单在 ...

  5. iOS开发——Autolayout下动态调整单元格高度

    情景描述: 有时候我们希望更新某一个单元格的数据,通常的做法是使用reloadData方法更新整个单元格.但是对一些情况是不适用的或者说实现起来比较麻烦.比如说这种简单的"点开"一 ...

  6. iOS开发初级课程

    iOS开发初级课程 针对学员 掌握Objective  C,C或者C++,有语言基础的学员,想从事iOS开发工作. iOS开发那些事-了解iOS开发(8集) 在课程中,我们首先介绍如何使用nib和故事 ...

  7. 【转】 学习ios(必看经典)牛人40天精通iOS开发的学习方法【2015.12.2

    原文网址:http://bbs.51cto.com/thread-1099956-1.html 亲爱的学员们: 如今,各路开发者为淘一桶金也纷纷转入iOS开发的行列.你心动了吗?想要行动吗?知道如何做 ...

  8. iOS开发实践-OOM治理

    概览 说起iOS的OOM问题大家第一想到的应该更多的是内存泄漏(Memory Leak),因为无论是从早期的MRC还是2011年Apple推出的ARC内存泄漏问题一直是iOS开发者比较重视的问题,比如 ...

  9. XE7 & IOS开发之开发账号(3):证书、AppID、设备、授权profile的申请使用,附Debug真机调试、Ad hoc下iPA文件生成演示(XCode5或以上版本推荐,有图有真相)

    网上能找到的关于Delphi XE系列的移动开发的相关文章甚少,本文尽量以详细的图文内容.傻瓜式的表达来告诉你想要的答案. 原创作品,请尊重作者劳动成果,转载请注明出处!!! 注意,以下讨论都是以&q ...

  10. IOS 开发下拉刷新和上拉加载更多

    IOS 开发下拉刷新和上拉加载更多 简介 1.常用的下拉刷新的实现方式 (1)UIRefreshControl (2)EGOTTableViewrefresh (3)AH3DPullRefresh ( ...

随机推荐

  1. ASP.NET中后台数据和前台控件的绑定

    关于ASP.NET中后台数据库和前台的数据控件的绑定问题 最近一直在学习个知识点,自己创建了SQL Server数据库表,想在ASP.NET中连接数据库,并把数据库中的数据显示在前台,注意,这里的数据 ...

  2. 基于位图(Bitmap、BitmapData)的图片处理方法(C#)

    目前操作位图的主流方法有三种: 1.基于Bitmap像素的处理方法,以GetPixel()和SetPixel()方法为主.方法调用简单,但是效率偏低. 2.基于内存的像素操作方法,以System.Ru ...

  3. ArcGIS Engine开发之鹰眼视图

    鹰眼是GIS软件的必备功能之一.它是一个MapControl控件,主要用来表示数据视图中的地理范围在全图中的位置. 鹰眼一般具有的功能: 1)鹰眼视图与数据视图的地理范围保持同步. 2)数据视图的当前 ...

  4. android AsynTask处理返回数据和AsynTask使用get,post请求

    Android是一个单线程模型,Android界面(UI)的绘制都只能在主线程中进行,如果在主线程中进行耗时的操作,就会影响UI的绘制和事件的响应.所以在android规定,不可在主线中进行耗时操作, ...

  5. React Native FlexBox

    FlexBox 是React Native布局的一种算法,目的是为了适配不同尺寸的屏幕而设计的. 使用时最关键的就是flex关键字的用法. flex用于修饰当前View在父视图中的占比. 占比如何计算 ...

  6. [数据科学] 从text, json文件中提取数据

    文本文件是基本的文件类型,不管是csv, xls, json, 还是xml等等都可以按照文本文件的形式读取. #-*- coding: utf-8 -*- fpath = "data/tex ...

  7. 【mysql】关于binlog格式

    写在前面的话 1.推荐用mixed,默认使用statement,基于上下文  set session/global binlog_format=mixed; 2.二进制日记录了数据库执行更改的操作,如 ...

  8. [已解决]Windows10 系统下HDMI 显示器 没有声音输出的奇怪问题

    今天想用一下显示器自带的喇叭,忽然发现声音输出选项里HDMI的声音设备没了.之前开始使用这台显示器的时是用过一段时间的. 百度了一番,没发现什么线索.后来去谷歌找到这么一段文字: I'm not su ...

  9. 分布式搜索引擎Elasticsearch性能优化与配置

    1.内存优化 在bin/elasticsearch.in.sh中进行配置 修改配置项为尽量大的内存: ES_MIN_MEM=8g ES_MAX_MEM=8g 两者最好改成一样的,否则容易引发长时间GC ...

  10. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...