http://shavekevin.com/2016/04/12/iosdeveloptips/

1.取消cell的分割线

tableview.separatorStyle = UITableViewCellSeparatorStyleNone;

2.UITabelviewCell 的高亮状态的取消
用以下方法:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{//设置cell的背景是透明的。 cell.backgroundColor = [UIColor clearColor]; //取消cell的高亮状态 cell.selectionStyle = UITableViewCellSelectionStyleNone; } //使用下面的这个方法会导致cell不能响应点击事件 - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } 

3.设置分割线的左右偏移量

tableview  setSeparatorInset:inset

4.类的声明和实现,书写的时候。容易犯的错误有一下几种情况。

(1).只写声明,不写实现。

(2).将@end这个结束标记忘记了。

(3).类的声明或者实现都不能写下C语言的函数中。

(4).属性的声明必须写在大括号中。

(5).在声明属性的时候,不能够直接赋值。

(6).声明和实现不能够嵌套使用。

5.更换头像后,好友不会立马看到我们更换的新头像。请问使用来哪种机制来更新本地的缓存。

IM透传 发个消息过去 携带新头像 好友接到后更新。

6.推送如何跳转到对应的controller

跳转界面

- (void)push:(NSDictionary *)params
{// 类名NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]]; const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding]; // 从一个字串返回一个类 Class newClass = objc_getClass(className); if (!newClass) { // 创建一个类 Class superClass = [NSObject class]; newClass = objc_allocateClassPair(superClass, className, 0); // 注册你创建的这个类 objc_registerClassPair(newClass); } // 创建对象 id instance = [[newClass alloc] init]; // 对该对象赋值属性 NSDictionary * propertys = params[@"property"]; [propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // 检测这个对象是否存在该属性 if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) { // 利用kvc赋值 [instance setValue:obj forKey:key]; } }]; // 获取导航控制器 UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController; UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex]; // 跳转到对应的控制器 [pushClassStance pushViewController:instance animated:YES]; } 

检测对象是否存在该属性

- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName
{unsigned int outCount, i; // 获取对象里的属性列表 objc_property_t * properties = class_copyPropertyList([instance class], &outCount); for (i = 0; i < outCount; i++) { objc_property_t property =properties[i]; // 属性名转成字符串 NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; // 判断该属性是否存在 if ([propertyName isEqualToString:verifyPropertyName]) { free(properties); return YES; } } free(properties); return NO; } 

来源于简书: iOS 万能跳转界面方法 runtime实用篇一

7.3D效果 还不错哦

https://github.com/nicklockwood/iCarousel

8.xcode7引入xmpp提示module libxmlsimu not found怎么解决?

解决方案如下图:

9.data进行MD5 加密

https://github.com/shaojiankui/iOS-Categories/blob/master/Categories/Foundation/NSData/NSData%2BHash.m

10.UIVisualEffectView 背景是虚化的(类似我们iphone查看通知时的虚化背景)

https://github.com/nicklockwood/FXBlurView

11.NSDate 的坑

Also when using a date format string using the correct format is important.

@"YYYY" is week-based calendar year.

@"yyyy" is ordinary calendar year.

可以看下面这篇博客:NSDateFormatter 'YYYY' 和 'yyyy' 的区别

12.swift 实时滤镜

http://blog.csdn.net/zhangao0086/article/details/39433519

13.动态加载视频

http://www.jianshu.com/p/3dcebf0493d1

14.swift 闭包

http://www.henishuo.com/closures-of-swift/

15.理解contentsScale

http://joeshang.github.io/2015/01/10/understand-contentsscale/#disqus_thread

16.图文混排

https://github.com/12207480/TYAttributedLabel

17.取消所有请求

[NSObject cancelPreviousPerformRequestsWithTarget:selfselector:@selector(sendContentReqData)object:nil];

18.刷新tableView某一行

[m_tableView reloadRowsAtIndexPaths:[NSArrayarrayWithObject:[NSIndexPathindexPathForRow:m_selectRowinSection:0]]withRowAnimation:UITableViewRowAnimationRight];

19.textField 文字上下居中

textField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;//.全部删除按钮textField.clearButtonMode =UITextFieldViewModeWhileEditing;[textFieldsetAutocapitalizationType:UITextAutocapitalizationTypeNone];

20.模拟导航条颜色

 UINavigationBar *tmpNavBar=[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44)]; tmpNavBar.barStyle=UIBarStyleDefault; self.m_navigationBar=tmpNavBar; UINavigationItem *tmpNavItem=[[UINavigationItemalloc]initWithTitle:@"Search"]; UIBarButtonItem *tmpBarItem=[[UIBarButtonItem alloc]initWithTitle:@"Done"style:UIBarButtonItemStyleDone target:selfaction:@selector(exitSearchScreen)]; [tmpNavItem setRightBarButtonItem:tmpBarItem]; [m_navigationBar setItems:[NSArray arrayWithObject:tmpNavItem]]; [self addSubview:m_navigationBar]; 

21.数组、字典内容不能为空,装的是地址,为空就是野指针

22.数组,字典访问不能越界

23.代理最好在dealloc里设置为nil,单例必须设置,因为一个类释放了,但是单例指针还指向这个类,可能会出问题。

24.防止野指针,代理处崩溃多为此现象。

25.字符串判断不为空,一般 str!= nil && ![str isEqualTo@""] , 不等于nil是有地址,后者是内容不为空。

26.下面的view或self.view如果小于上面的,上面的view超过下面的部分将无法与用户交互。

27.自定义cell时,最好在cell.contentView上加控件

28.尽量使用点语法,减少内存泄漏

29.正则

(?<=src\s*\=\s*\")[\d\D]+?(?=\")

取出html 中的src 图片

30.不能重复释放

31.两个对象不能相互引用

32.dealloc的super dealloc必须放在最后面

33.所有不带星号的和id类型的都只能assign

34.系统线程也有副线程

35.一些变量最好都初始化,且写在一个方法里,需要恢复开始的状态时可以直接调用该方法恢复

36.初始化的指针都要赋值为nil,系统不会帮你这么做的

37.block 对象语法

(1).在内联Block Objects可以直接读取对象self,独立的BlockObjects若想读取self对象必须将其设置为参数传递进去。

(2).在内联Block Objects可以直接用点语法读取对象self的属性,也可以使用setter和 getter方法,但是,独立的Block Objects只能用setter and getter方法读取对象self的属性

38.改变导航条颜色

[nav.navigationBar setTintColor:[UIColorgrayColor]];nav.navigationBar.barStyle =UIBarStyleBlackTranslucent;

39.程序崩溃处理方法

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);}

调用下面的方法,如数组越界,调用不存在的方法等会打出详细的信息。

void UncaughtExceptionHandler(NSException*exception) {NSArray *arr = [exception callStackSymbols];NSString *reason = [exception reason];NSString *name = [exception name]; NSLog(@"\nname: %@\reason: %@\nuserInfo: %@\ncallStackSymbols:%@\ncallStackReturnAddresses: %@",name,reason,[exceptionuserInfo],arr,[exceptioncallStackReturnAddresses]); } 

开启僵尸模式 Object-C的Enable Zombie Objects勾选,Memory 中的MallocStack勾选,Exceptions里的Log Exceptions勾选

40.NSLog 怎么打印出变量类型的?

NSStringFromSelector(SEL aSelector);NSSelectorFromString(NSString *aSelectorName);NSStringFromClass(Class aClass);NSClassFromString(NSString *aClassName);NSStringFromProtocol(Protocol *proto)NSProtocolFromString(NSString *namestr) NSStringFromCGPoint(CGPoint point);NSStringFromCGVector(CGVector vector);NSStringFromCGSize(CGSize size); NSStringFromCGRect(CGRect rect); NSStringFromCGAffineTransform(CGAffineTransform transform); NSStringFromUIEdgeInsets(UIEdgeInsets insets); NSStringFromUIOffset(UIOffset offset); CGPointFromString(NSString *string); CGVectorFromString(NSString *string); CGSizeFromString(NSString *string); CGRectFromString(NSString *string); CGAffineTransformFromString(NSString *string); UIEdgeInsetsFromString(NSString *string); UIOffsetFromString(NSString *string); 

转载于:https://www.cnblogs.com/superbobo/p/5392088.html

iOS开发中的小Tips相关推荐

  1. 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新。

    UITableView的Group样式下顶部空白处理//分组列表头部空白处理 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ...

  2. 项目开发中的小tips

    2019独角兽企业重金招聘Python工程师标准>>> 一.泛型通配符:"?" java泛型中,当某种类型不确定时,可以使用未知类型?来代替,在Java集合框架中 ...

  3. 一些IOS开发中的小技巧

    1.打包后提交报错误 错误信息:ERROR ITMS-90035: "Invalid Signature. Code object is not signed at all. The bin ...

  4. iOS开发中一些有用的小代码

    1.判断邮箱格式是否正确的代码: //利用正则表达式验证 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex = @&quo ...

  5. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  6. iOS 开发中的多线程

    线程.进程 什么是线程.进程   有的人说进程就像是人的脑袋,线程就是脑袋上的头发~~.其实这么比方不算错,但是更简单的来说,用迅雷下载文件,迅雷这个程序就是一个进程,下载的文件就是一个线程,同时下载 ...

  7. iOS开发UI篇—iOS开发中三种简单的动画设置

    [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要"参与到"动画中 [UIView beginAnimations: ...

  8. 在iOS开发中使用FMDB

    在iOS开发中使用FMDB 前言 SQLite (http://www.sqlite.org/docs.html) 是一个轻量级的关系数据库.iOS SDK 很早就支持了 SQLite,在使用时,只需 ...

  9. iOS开发中键盘样式和自定义键盘。

    文章目录 系统自带的样式 自定义键盘 在系统自带键盘基础上自定义键盘 完全自定义键盘 自定义全部类型键盘 系统自带的样式 在iOS开发中系统自带键盘已经有很多样式,但是有时候并不能满足我们都开发需求, ...

  10. iOS开发中常用的方法

    iOS开发中常用的方法 系统弹窗: 过期方法: UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"确认报价" ...

最新文章

  1. QuickBI助你成为分析师-数据建模(一)
  2. acm之简单博弈 Nim Bash Wythoff
  3. boost::fusion::iterator_range用法的测试程序
  4. python是如何实现进程池和线程池的_进程、线程、线程池和协程如何理解?
  5. 设计模式的Java 8 Lambda表达式–命令设计模式
  6. c语言入门数据类型详解,C语言的基本数据类型入门教程
  7. Yahoo!用户体验与设计前副总裁推荐——《设计模式》
  8. Spring boot 开发 GA/T1400 协议之注册、保活、注销、校时功能
  9. html表格内数据填充颜色,点击数据,自动为整行表格填充颜色,再也不用担心看错数据了...
  10. Low-Resource Knowledge-Grounded Dialogue Generation_biji
  11. 区域划分问题(数学题)
  12. 朋友圈那个随便辞职的年轻人,后来活成了什么样?
  13. 让座席管理工作听得见也看得着
  14. Unity3D学习—牧师与魔鬼—MVC模式和ECS架构应用
  15. java解压报错java.io.IOException: failed to skip current tar entry
  16. android alarmmanager后台,Android AlarmManager实现定时循环后台任务
  17. 程序员老黄历Java源码实现
  18. Win7 系统下进入Debug
  19. Windows Mobile 6 模拟器上网设置
  20. Linux Redis清理缓存

热门文章

  1. 基于Java的外卖订餐平台
  2. Java TCP案例网络聊天室
  3. Arthas 实战,助你解决同名类依赖冲突问题
  4. 适配器模式之门面模式
  5. CSS3 box-shadow 设置元素阴影、text-shadow 设置文本阴影
  6. sql查询数据库所有表、字、注释
  7. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_14-页面静态化-数据模型-远程请求接口...
  8. 创建WEBPARTS全过程
  9. idea 项目启动找不到页面问题和run/debug只能启动一个的问题
  10. ActiveMQ学习笔记(1)----初识ActiveMQ