IOS开发基础知识--碎片8
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的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片50
1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
- IOS开发基础知识--碎片40
1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...
随机推荐
- 【原创】数据挖掘案例——ReliefF和K-means算法的医学应用
数据挖掘方法的提出,让人们有能力最终认识数据的真正价值,即蕴藏在数据中的信息和知识.数据挖掘 (DataMiriing),指的是从大型数据库或数据仓库中提取人们感兴趣的知识,这些知识是隐含的.事先未知 ...
- 在 ML2 中配置 Vlan Network- 每天5分钟玩转 OpenStack(93)
上一节我们学习了 Neutron Vlan Network 的原理,今天讨论如何在 ML2 配置中 enable 它. 首先在 /etc/neutron/plugins/ml2/ml2_conf.in ...
- Java-Spring:java.lang.ClassCastException: com.sun.proxy.$Proxy* cannot be cast to***问题解决方案
java.lang.ClassCastException: com.sun.proxy.$Proxy* cannot be cast to***问题解决方案 临床表现: 病例: 定义代理类: @Tra ...
- Javascript常用正则表达式汇总
一.匹配数字和字符串 整数或者小数:^[0-9]+\.{0,1}[0-9]{0,2}$ 只能输入数字:"^[0-9]*$". 只能输入n位的数 字:"^\d{n}$&qu ...
- 常见的几个meta标签元素
1.指定字符集: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/& ...
- 机器学习 1 linear regression 作业
话说学机器学习,不写代码就太扯淡了.好了,接着上一次的线性回归作业. hw1作业的链接在这: http://speech.ee.ntu.edu.tw/~tlkagk/courses/ML_2016/L ...
- 《C#并发编程经典实例》笔记
1.前言 2.开宗明义 3.开发原则和要点 (1)并发编程概述 (2)异步编程基础 (3)并行开发的基础 (4)测试技巧 (5)集合 (6)函数式OOP (7)同步 1.前言 最近趁着项目的一段平稳期 ...
- Linux iptables原理--数据包流向
Iptable与Netfilter 在上一篇文章 linux iptables常用命令--配置一个生产环境的iptables 我们知道iptables有好几个表,如raw,mangle,nat,fil ...
- LINQ to SQL语句(16)之对象标识
对象标识 运行库中的对象具有唯一标识.引用同一对象的两个变量实际上是引用此对象的同一实例.你更改一个变量后,可以通过另一个变量看到这些更改. 关系数据库表中的行不具有唯一标识.由于每一行都具有唯一的主 ...
- C#新手常犯的错误
虽然这篇post的标题是新手常犯的错误,实际上很多有经验的程序员也经常犯这些错误,我整理了一下,就当是笔记.1.遍历List的错误,比如如下代码: List<String> strList ...