当前位置: 首页 > news >正文

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(0, 0, 320, 44)];
   navLabel.text = @"团购详情";
   navLabel.textColor = [UIColor whiteColor];
   navLabel.font = [UIFont systemFontOfSize:18];
   navLabel.textAlignment = NSTextAlignmentCenter;
   self.navigationItem.titleView = navLabel;
    
   //右边收藏按钮
   UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
   rightButton.frame = CGRectMake(0, 0, 20, 20);
   [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(0, 0, 30, 40);
   [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/255 green:1.0/255 blue:1.0/255 alpha:1], UITextAttributeTextColor,[UIColor clearColor],UITextAttributeTextShadowColor,[UIFont systemFontOfSize:20],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

 

转载于:https://www.cnblogs.com/wujy/p/4305755.html

相关文章:

  • 远程debug WebSphere 和 Watch时提示error(s)_during_the_evaluation
  • javascirpt怎样模仿块级作用域(js高程笔记)
  • python 多线程编程
  • 一:Html基本结构
  • ETL的考虑
  • sass学习(2)——关于变量
  • C# 语言基础(转义字符)
  • 第一天开通博客园
  • iOS开发之进阶指南 持续更新
  • 服务器安装2个tomcat
  • html字符实体
  • java 常用资源
  • 读入外挂——秒杀scanf
  • div模拟 select 或者 其他表单组件
  • Android下gradle编译代码及混淆
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • Centos6.8 使用rpm安装mysql5.7
  • GraphQL学习过程应该是这样的
  • isset在php5.6-和php7.0+的一些差异
  • Js基础知识(四) - js运行原理与机制
  • magento 货币换算
  • Netty源码解析1-Buffer
  • Promise面试题2实现异步串行执行
  • Selenium实战教程系列(二)---元素定位
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • Xmanager 远程桌面 CentOS 7
  • 阿里研究院入选中国企业智库系统影响力榜
  • 第2章 网络文档
  • 将回调地狱按在地上摩擦的Promise
  • 浅谈web中前端模板引擎的使用
  • 探索 JS 中的模块化
  • 优秀架构师必须掌握的架构思维
  • 阿里云ACE认证学习知识点梳理
  • !!Dom4j 学习笔记
  • (delphi11最新学习资料) Object Pascal 学习笔记---第7章第3节(封装和窗体)
  • (LeetCode 49)Anagrams
  • (附源码)spring boot基于Java的电影院售票与管理系统毕业设计 011449
  • (免费分享)基于springboot,vue疗养中心管理系统
  • (七)Knockout 创建自定义绑定
  • (四) Graphivz 颜色选择
  • (转)程序员技术练级攻略
  • ***linux下安装xampp,XAMPP目录结构(阿里云安装xampp)
  • .NET中使用Redis (二)
  • ??javascript里的变量问题
  • @AliasFor注解
  • @data注解_一枚 架构师 也不会用的Lombok注解,相见恨晚
  • [2010-8-30]
  • [51nod1610]路径计数
  • [BZOJ3223]文艺平衡树
  • [C++]priority_queue的介绍及模拟实现
  • [DevOps云实践] 彻底删除AWS云资源
  • [dts]Device Tree机制
  • [github配置] 远程访问仓库以及问题解决
  • [GN] Vue3.2 快速上手 ---- 核心语法2
  • [html] 动态炫彩渐变背景