1:用UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件。

解决办法:UIImageView默认的UserInteractionEnabled是NO,把它修改成YES,或者可以直接在XCODE上面的view有个属性勾选User Interaction Enabled

遇到的场景(在滚动视图里面放一个图片视图,在图片视图上又放置一个按键,发现一直没有响应效果);

2:AFnetWorking报"Request failed: unacceptable content-type: text/html"

对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:

AFURLResponseSerialization.m文件

223行:

self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];

加上@"text/html",部分,其实就是添加一种服务器返回的数据格式。

3:NSMutableArray和NSArray的相互转换

// NSArray --> NSMutableArray
NSMutableArray *myMutableArray = [myArray mutableCopy]; // NSMutableArray --> NSArray
NSArray *myArray = [myMutableArray copy];

4:自定义系统导航条上面的返回按钮,以及文字,右侧收藏按钮

 //中间标题
UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
navLabel.text = @"团购详情";
navLabel.textColor = [UIColor whiteColor];
navLabel.font = [UIFont systemFontOfSize:];
navLabel.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = navLabel; //右边收藏按钮
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(, , , );
[rightButton setBackgroundImage:LOAD_IMAGE(@"meishoucang") forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(doShouCang) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightItem; //左边返回按钮
UIButton *fanHuiButton = [UIButton buttonWithType:UIButtonTypeCustom];
fanHuiButton.frame = CGRectMake(, , , );
[fanHuiButton setBackgroundImage:LOAD_IMAGE(@"fanhuijiantou") forState:UIControlStateNormal];
[fanHuiButton addTarget:self action:@selector(doFanHui) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:fanHuiButton];
self.navigationItem.leftBarButtonItem = leftItem; 导航条上的title字体, 字号 可以这么定义,完全使用系统的
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:1.0/ green:1.0/ blue:1.0/ alpha:], UITextAttributeTextColor,[UIColor clearColor],UITextAttributeTextShadowColor,[UIFont systemFontOfSize:],UITextAttributeFont,nil]];

5:清理UITableView底部空的列

self.tableView.tableFooterView = [[UIView alloc] init];

6:如何隐藏navigation跳转后的头部右键

//隐藏头部左边的返回
self.navigationItem.hidesBackButton=YES;
//隐藏头部右边
self.navigationItem.rightBarButtonItem.customView.hidden=YES;

7:如要给UICollectionViewController视图设置背景图

UIImage *image=[UIImage imageNamed:@"AppBg"];
self.collectionView.layer.contents=(id)image.CGImage;

8:可以在其它地方修改rootViewController

UIWindow *window = [UIApplication sharedApplication].keyWindow;
window.rootViewController = [[HVWTabBarViewController alloc] init];

9:新浪微博授权登录报Warning: Attempt to present on whose view is not in the window hierarchy!

 IntroductoryViewController *introductory=[mainStoryboard instantiateViewControllerWithIdentifier:@"introductoryview"];
UINavigationController *rootNavigationController=[[UINavigationController alloc] initWithRootViewController:introductory];
self.window.rootViewController=rootNavigationController; 主要问题是a跳转到b,然后b放一个授权新浪微博的按键,增加一个UINavigationController,然后在a跳转到b时用nav跳转: UIStoryboard *mainStoryboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController* loginviewControll=[mainStoryboard instantiateViewControllerWithIdentifier:@"loginviewcontroller"];
[self.navigationController pushViewController:loginviewControll animated:YES];

10:在引入第三方TcweiboSDK报linker command failed with exit code1(use -v to see invocation)

是因为重复引入libTCWeiboSDK这个类库,TARGETS-PROJECT-Build Phases-Link Binary With Libraries中,有三个libTcweiboSDK,可以删除libTCWeiboSDK-I386.a

11:NSUserDefaults存放民NSDictionary

注意:NSUserDefaults支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型。
本次遇到的问题:当NSDictionary里面的值为null时,要写入NSUserDefaults会报异常(attempt to insert non-property list object);
解决方式:把字典中的值进行过滤处理,为空的转化成字符串的空值;代码如下(创建一个扩展类): @implementation NSDictionary(Common)
-(NSDictionary *) changeDictionaryNotNill
{
NSMutableDictionary *muResult=[[NSMutableDictionary alloc]init];
NSEnumerator *enumerator=[self keyEnumerator];
id key;
while ((key=[enumerator nextObject])) {
id value=[self objectForKey:key];
if ((NSNull *)value==[NSNull null]) {
[muResult setObject:@"" forKey:key];
}
else
{
[muResult setObject:value forKey:key];
}
}
return muResult;
}
@end

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

  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. 趣谈unicode,ansi,utf-8,unicode big endian这些编码有什么区别(转载)

    从头讲讲编码的故事.那么就让我们找个草堆坐下,先抽口烟,看看夜晚天空上的银河,然后想一想要从哪里开始讲起.嗯,也许这样开始比较好…… 很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同 ...

  2. Jackson的简单用法

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1简介 Jackson具有比较高的序列化和反序列化效率,据测试,无论是 ...

  3. 【集合框架】JDK1.8源码分析之Collections && Arrays(十)

    一.前言 整个集合框架的常用类我们已经分析完成了,但是还有两个工具类我们还没有进行分析.可以说,这两个工具类对于我们操作集合时相当有用,下面进行分析. 二.Collections源码分析 2.1 类的 ...

  4. reactjs学习之路

    正式开始react的学习 1.react中组件的首字母如果是大写就会当成自定义组件,如果是小写就会当成DOM的自带元素名.如果你自定义组件名称首字母是小写不会报错,但是无法显示. 2.自定义组件的re ...

  5. 【JS】heatmap.js v1.0 到 v2.0,详细总结一下:)

    前段时间,项目要开发热力图插件,研究了heatmap.js,打算好好总结一下. 本文主要有以下几部分内容: 部分源码理解 如何迁移到v2.0 v2.0官方文档译文 关于heatmap.js介绍,请看这 ...

  6. SSE指令集优化学习:双线性插值

    对SSE的学习总算迈出了第一步,用2天时间对双线性插值的代码进行了优化,现将实现的过程梳理以下,算是对这段学习的一个总结. 1. 什么是SSE 说到SSE,首先要弄清楚的一个概念是SIMD(单指令多数 ...

  7. C# BitArray

    使用C#实现Huffman对文件进行压缩和解压缩,那个对Huffman编码后的01串没找到好的方法来保存,就很愚蠢的使用字符串保存"01"串,功能实现了,但是感觉总是有些别扭.就搜 ...

  8. Compute Resource Consolidation Pattern 计算资源整合模式

    Consolidate multiple tasks or operations into a single computational unit. This pattern can increase ...

  9. jQuery-1.9.1源码分析系列(十四) 一些jQuery工具

    为了给下一章分析动画处理做准备,先来看一下一些工具.其中队列工具在动画处理中被经常使用. jQuery.fn. queue(([ queueName ] [, newQueue ]) || ([ qu ...

  10. “全能”选手—Django 1.10文档中文版Part2

    第一部分传送门 第三部分传送门 第四部分传送门 3.2 模型和数据库Models and databases 3.2.2 查询操作making queries 3.3.8 会话sessions 目录 ...