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. Android NDK开发Hello Word!

    在之前的博客中已经为大家介绍了,如何在win环境下配置DNK程序,本篇我将带大家实现一个简单的Hello jni程序,让大家真正感受一下NDK开发的魅力.这里我们选择使用C+JAVA开发Android ...

  2. 剖析width、height继承

    在CSS这个一切皆为框的世界里,我们今天再来探究探究width与height. 我靠,width与height有什么好探究的,不就是设定元素的宽.高吗?大不了还要区分标准盒子模型和IE盒子模型的区别, ...

  3. CSS3中border-radius、box-shadow与gradient那点事儿

    一.border-radius border-radius用于添加圆角边框,用处非常广泛. 1)一个值,代表了四个角 .radius-one { /* Safari 3-4, iOS 1-3.2, A ...

  4. HTML 网页特效CSS大全

    css属性代码大全一CSS文字属性:color : #999999; /* 文字颜色*/font-family : 宋体,sans-serif; /* 文字字体*/font-size : 9pt; / ...

  5. js实现可拖拽的div

    前言 下午忙里偷闲想写一个可拖拽的例子,留在脑海里一直都是三个事件mouseDown,mouseUp,mouseMove, 但从没有动手实践过,今天想起了自己实践了并学习了张鑫旭的demo实现. 学习 ...

  6. 函数----Beginning Visual C#

    span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...

  7. MVC利用MvcHtmlString在后台生成HTML

    后台: /// <summary> /// 生成分类下拉-列表框,选中指定的项 /// </summary> /// <param name="html&quo ...

  8. spring in action 4th --- quick start

    读spring in action. 环境搭建 quick-start依赖注入 面向切面 1.环境搭建 jdk1.8 gradle 2.12 Intelij idea 2016.2.1 1.1创建一个 ...

  9. Halcon11与VS2010联合开发

    刚开始学习Halcon,需要使用Halcon与C++联合开发软件,查了网上的资料都是Halcon10的,我用的是Halcon11和VS2010的开发环境,实践了一下发现有一些问题,于是把自己的配置的过 ...

  10. 怎样使用My97日期控件

    有网友说无法使用My97日期控件,Insus.NET测试一下,是可以正常使用了. 在ASP.NET MVC环境中测试. 去官网下载My97日期控件程序包: 下载解压之后,把程序的目录拷贝至projec ...