关于UIScrollView有些你很难知晓的崩溃情形

为了实现以下的功能(按钮之间的切换效果):

简短的代码如下:

//
// RootViewController.m
// BUG
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h" @interface RootViewController () {
UIView *_showView;
} @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; _showView = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:_showView]; NSArray *title = @[@"YouXianMing",
@"XianHui",
@"XianMing",
@"XianNeng",
@"XianRen"]; [title enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// 初始化button
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(, *(idx + ), , )];
button.layer.borderWidth = .f;
[_showView addSubview:button]; // 设置字体
button.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin"
size:.f]; // 设置标题以及标题颜色
[button setTitle:obj
forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor]
forState:UIControlStateNormal]; // 添加事件
[button addTarget:self
action:@selector(buttonsEvent:)
forControlEvents:UIControlEventTouchUpInside];
}];
} - (void)buttonsEvent:(UIButton *)button
{
[_showView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIButton *tmpButton = obj; if ([tmpButton isEqual:button])
{
[tmpButton setTitleColor:[UIColor redColor]
forState:UIControlStateNormal];
}
else
{
[tmpButton setTitleColor:[UIColor blackColor]
forState:UIControlStateNormal];
}
}];
} @end

之后,将UIView替换成UIScrollView后:

然后就会崩溃-_-!!

崩溃信息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setTitleColor:forState:]: unrecognized selector sent to instance 0xa590390'

崩溃原因是_showView.subviews里面有一个UIImageView

我们并没有添加这个东西UIImageView到subviews中呢,其实,这个东西是UIScrollView自己的一个东西......

写上以下保护性语句就没问题了.

话说,UIScrollView跟你偷偷加了点东西让你崩溃了都不知道咋回事-_-!!!

最新文章

  1. 可以正确显示表格线的Grid item view
  2. Swift处理堆栈问题——给定两组序列,其中一个序列表示栈的push 顺序,判断另一个序列有没有可能是对应的pop 顺序
  3. 关于Thomas Brinkhoff移动对象生成器的修改
  4. 2016-06-13:NAT原理
  5. Oracle定时执行存储过程
  6. IE 9渲染overflow的bug及解决
  7. git 提交远程
  8. bootchart--检测linux启动性能的软件
  9. 应用Observer接口实践Observer模式
  10. 自适应Simpson积分
  11. 分布式版本库——Windows下Git的环境部署以及在GitHub上开源自己的项目
  12. 十九. 想快速开发app,需要找外包吗?
  13. 零基础学Python--------第8章 模块
  14. 微信小程序wx.previewImage实用案例(交流QQ群:604788754)
  15. JUC同步锁(五)
  16. 弱智的grub消除法
  17. 小甲鱼Python第八讲课后习题
  18. (转)SSIS_数据流转换(Union All&合并联接&合并)
  19. 关于在线文本编辑器防XSS注入攻击问题
  20. rest-framework框架之序列化

热门文章

  1. python笔记07-----打包模块(shutil,zipfile,tarfile)
  2. @Override 注解compiler1.5和compiler1.6不同
  3. mysql数据库数据监测
  4. Java 和 JSP 实现网站访问量统计 (刷新过滤)
  5. Codeforces 960G. Bandit Blues
  6. Linux 命令 "cp" 代码实现简介
  7. java linux ssh jar
  8. c#中的out和ref
  9. SQL Server提取字段中的所有数字
  10. Vertica示例数据库安装