1:两种方法删除NSUserDefaults所有记录

  1. //方法一
  2. NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
  3. [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
  4.  
  5. //方法二
  6. - (void)resetDefaults {
  7. NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
  8. NSDictionary * dict = [defs dictionaryRepresentation];
  9. for (id key in dict) {
  10. [defs removeObjectForKey:key];
  11. }
  12. [defs synchronize];
  13. }

2:设置全局navigation barbuttonitem

  1. #pragma mark 设置全局navigation barbuttonitem
  2. -(void)setNaviBarButtonItemImage:(NSString *)imageName andX:(NSInteger)x andY:(NSInteger)y andW:(NSInteger)w andH:(NSInteger)h andTitle:(NSString *)title andSel:(SEL)sel andLOrR:(NSString *)lOr andTitleColor:(UIColor *)color{
  3.  
  4. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  5. btn.frame =CGRectMake(x,y,w,h);
  6.  
  7. [btn setTitle:title forState:UIControlStateNormal];
  8.  
  9. if (imageName.length== && title.length==) {
  10.  
  11. } else if (imageName.length== && title.length!=) {
  12. [btn setBackgroundColor:[UIColor clearColor]];
  13. [btn setTitleColor:color forState:UIControlStateNormal];
  14. }else if(imageName.length!= && title.length==){
  15. UIImage *image = [UIImage imageNamed:imageName];
  16. [btn setImage:image forState:UIControlStateNormal];
  17. }else if(imageName.length!= && title.length!=){
  18. UIImage *image = [UIImage imageNamed:imageName];
  19. [btn setBackgroundImage:image forState:UIControlStateNormal];
  20. [btn setBackgroundColor:[UIColor clearColor]];
  21. [btn setTitleColor:color forState:UIControlStateNormal];
  22. }
  23.  
  24. [btn addTarget: self action:sel forControlEvents: UIControlEventTouchUpInside];
  25. UIBarButtonItem *bBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
  26.  
  27. if ([lOr isEqualToString:@"left"]) {
  28. [self.navigationItem setLeftBarButtonItem:bBtn];
  29. }else{
  30. [self.navigationItem setRightBarButtonItem:bBtn];
  31. }
  32. }

3:UITableView设置Section间距

  1. 在使用IOSUITableView时,时常会用到它的UITableViewStyleGrouped分组多section属性。而默认的情况下使用该属性后section之间的间距会比较大,看着很不舒服。那么可以通过以下的代理方法配置UITableView各个section的间距。
  2.  
  3. 原理其实很简单,显示效果的各个section间距其实是section头部和底部的组合。配置他们的间距就是配置各个section的头部和底部
  4.  
  5. //section头部间距
  6. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  7. {
  8. return ;//section头部高度
  9. }
  10. //section头部视图
  11. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  12. {
  13. UIView *view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
  14. view.backgroundColor = [UIColor clearColor];
  15. return [view autorelease];
  16. }
  17. //section底部间距
  18. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  19. {
  20. return ;
  21. }
  22. //section底部视图
  23. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  24. {
  25. UIView *view=[[UIView alloc] initWithFrame:CGRectMake(, , , )];
  26. view.backgroundColor = [UIColor clearColor];
  27. return [view autorelease];
  28. }

4:解决OBJC_CLASS_$_MBProgressHUD无法引用的问题

  1. 虽然用POD把相关文件已经更新下来,但它却没有引入到工程中,要手动对它进行引用(或者直接放弃pod管理此插件,直接引入工程项目源代码中)
  2.  
  3. Undefined symbols for architecture i386:
  4.  
  5. "_OBJC_CLASS_$_MBProgressHUD", referenced from:
  6.  
  7. objc-class-ref in ViewController.o
  8.  
  9. ld: symbol(s) not found for architecture i386
  10.  
  11. clang: error: linker command failed with exit code (use -v to see invocation)
  12.  
  13. 这里的错误是因为你的在building phases中没有引用相关的头文件,因此,只需要在building phase中添加对应的.m文件就可以了。

5:iOS7 下使用SVPullToRefresh 下拉刷新导航栏位置错误

  1. iOS7 下使用SVPullToRefresh 下拉刷新导航栏位置错误;下拉刷新之后,tableview的第一列会跑到导航栏的下面;修正:添加如下代码
  2.  
  3. /**
  4.  
  5. * 下拉刷新 增加一个;
  6.  
  7. */
  8.  
  9. //修复下拉刷新位置错误 代码开始
  10.  
  11. if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
  12.  
  13. self.automaticallyAdjustsScrollViewInsets = NO;
  14.  
  15. UIEdgeInsets insets = self.tableView.contentInset;
  16.  
  17. insets.top = self.navigationController.navigationBar.bounds.size.height +
  18.  
  19. [UIApplication sharedApplication].statusBarFrame.size.height;
  20.  
  21. self.tableView.contentInset = insets;
  22.  
  23. self.tableView.scrollIndicatorInsets = insets;
  24.  
  25. }
  26.  
  27. //修复下拉刷新位置错误 代码结束
  28.  
  29. __block RootViewController *bSelf = self;
  30.  
  31. [self.tableView addPullToRefreshWithActionHandler:^{
  32.  
  33. [bSelf addRows];
  34.  
  35. }];
  36.  
  37. /**
  38.  
  39. * 拉到最后 加载更多,增加一个;
  40.  
  41. */
  42.  
  43. [self.tableView addInfiniteScrollingWithActionHandler:^{
  44.  
  45. [bSelf addMoreRow];
  46.  
  47. }];

6:当改动布局要更新效果时

  1. CGRect headFrame=self.headerView.frame;
  2. headFrame.size.height=;
  3. self.headerView.frame = headFrame;
  4. [self.headerView setNeedsLayout];
  5. [self.headerView layoutIfNeeded];

7:给UITextField增加一个右边内的图片按键(rightView)

  1. UIButton *addCommentBtn=[[UIButton alloc]initWithFrame:CGRectMake(, , ,inputTextViewHeight)];
  2. [addCommentBtn setImage:[UIImage imageNamed:@"textViewEditNormal"] forState:UIControlStateNormal];
  3. [addCommentBtn addTarget:self action:@selector(addCommentAction) forControlEvents:UIControlEventTouchUpInside];
  4. _inputTextView.rightView=addCommentBtn;
  5. _inputTextView.rightViewMode=UITextFieldViewModeAlways;

8:NSLog 输出格式集合

  1.  %@     对象
  2. %d, %i    整数
  3. %u      无符整形
  4. %f       浮点/双字
  5. %x, %X   二进制整数
  6. %o      八进制整数
  7. %zu     size_t
  8. %p      指针
  9. %e      浮点/双字 (科学计算)
  10. %g      浮点/双字
  11. %s       C 字符串
  12. %.*s      Pascal字符串
  13. %c       字符
  14. %C       unichar
  15. %lld      64位长整数(long long
  16. %llu      无符64位长整数
  17. %Lf       64位双字

9:设置UIImage的渲染模式:UIImage.renderingMode

  1. 设置UIImage的渲染模式:UIImage.renderingMode
  2. 着色(Tint Color)是iOS7界面中的一个.设置UIImage的渲染模式:UIImage.renderingMode重大改变,你可以设置一个UIImage在渲染时是否使用当前视图的Tint ColorUIImage新增了一个只读属性:renderingMode,对应的还有一个新增方法:imageWithRenderingMode:,它使用UIImageRenderingMode枚举值来设置图片的renderingMode属性。该枚举中包含下列值:
  3. UIImageRenderingModeAutomatic  // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。  
  4. UIImageRenderingModeAlwaysOriginal   // 始终绘制图片原始状态,不使用Tint Color。  
  5. UIImageRenderingModeAlwaysTemplate   // 始终根据Tint Color绘制图片,忽略图片的颜色信息。  
  6. renderingMode属性的默认值是UIImageRenderingModeAutomatic,即UIImage是否使用Tint Color取决于它显示的位置。
  7. UIImage *img = [UIImage imageNamed:@ "myimage" ];  img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
  8. 使用场景(Toolbar中增加item,item使用背景图,会出现色调为蓝色,如果要为图片原来的色调,则要修改图片的渲染,因为目前是渲染成文字的色调):
  9. @property (weak, nonatomic) IBOutlet UIBarButtonItem *mycollectionItem;
  10.  
  11. UIImage *collectionItemImage=[UIImage imageNamed:@"bottomCollectionNormal"];
  12. collectionItemImage=[collectionItemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  13. self.mycollectionItem.image=collectionItemImage;

10:navigationController当前页隐藏后跳转回去页同样被隐藏

  1. 当前页隐藏代码:
  2. [self.navigationController setNavigationBarHidden:YES];
  3. 跳转时:
  4. [self.navigationController setNavigationBarHidden:NO];
  5. [self.navigationController popViewControllerAnimated:YES];

IOS开发基础知识--碎片9的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  5. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  6. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  7. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

  10. IOS开发基础知识--碎片40

    1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...

随机推荐

  1. SqlServer时间戳与普通格式的转换

    /********************************************** 时间戳转换(秒) ******************************************* ...

  2. php这是一个随机打印输出字符串的例子

    <?php header("Content-type:text/html;charset='utf8'"); error_reporting(E_ALL); define(& ...

  3. android 在使用ViewAnimationUtils.createCircularReveal()无法兼容低版本的情况下,另行实现圆形scale动画

    ViewAnimationUtils.createCircularReveal()的简介: ViewAnimationUtils.createCircularReveal()是安卓5.0才引入的,快速 ...

  4. C++ 与 php 的交互 之----- C++ 异步获取 网页文字内容,异步获取 php 的 echo 值。

    已搬迁至 http://www.cnblogs.com/linguanh/p/4543836.html

  5. Linux服务器(Ubuntu14.04)添加远程连接VNC Server

    1.打开终端输入:sudo apt-get install xrdp,   2. sudo apt-get install vnc4server ,  3. sudo apt-get install ...

  6. git安装和初次使用

    为了知道某人安装git,我也是重装啊. 1.下载git并安装 2.打开我的电脑,右键属性,选择高级设置,打开环境变量设置: 3.键盘输入窗口键+r,或者点击开始->运行 输入cmd 在新打开的命 ...

  7. Linux 学习笔记

    Linux学习笔记 请切换web视图查看,表格比较大,方法:视图>>web板式视图 博客园不能粘贴图片吗 http://wenku.baidu.com/view/bda1c3067fd53 ...

  8. react入门(1)

    这篇文章也不能算教程咯,就算是自己学习整理的笔记把. 关于react一些相关的简介.优势之类的,随便百度一下一大堆,我就不多说了,可以去官网(http://reactjs.cn/)看一下. 这片主要讲 ...

  9. [WCF编程]11.错误:错误契约

    一.错误传播 服务需要向客户端报告特定错误,当WCF默认的错误屏蔽方法并不包含这一实现.另一个重要的问题与传播到客户端有关,即由于异常是针对特定技术的,因此无法跨越服务边界而被共享.要实现无缝的互操作 ...

  10. Linux查看CPU和内存使用情况(转)

    在系统维护的过程中,随时可能有需要查看 CPU 使用率,并根据相应信息分析系统状况的需要.在 CentOS 中,可以通过 top 命令来查看 CPU 使用状况.运行 top 命令后,CPU 使用状态会 ...