关于UIScrollView有些你很难知晓的崩溃情形
2024-10-21 03:15:43
关于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跟你偷偷加了点东西让你崩溃了都不知道咋回事-_-!!!
最新文章
- 可以正确显示表格线的Grid item view
- Swift处理堆栈问题——给定两组序列,其中一个序列表示栈的push 顺序,判断另一个序列有没有可能是对应的pop 顺序
- 关于Thomas Brinkhoff移动对象生成器的修改
- 2016-06-13:NAT原理
- Oracle定时执行存储过程
- IE 9渲染overflow的bug及解决
- git 提交远程
- bootchart--检测linux启动性能的软件
- 应用Observer接口实践Observer模式
- 自适应Simpson积分
- 分布式版本库——Windows下Git的环境部署以及在GitHub上开源自己的项目
- 十九. 想快速开发app,需要找外包吗?
- 零基础学Python--------第8章 模块
- 微信小程序wx.previewImage实用案例(交流QQ群:604788754)
- JUC同步锁(五)
- 弱智的grub消除法
- 小甲鱼Python第八讲课后习题
- (转)SSIS_数据流转换(Union All&;合并联接&;合并)
- 关于在线文本编辑器防XSS注入攻击问题
- rest-framework框架之序列化
热门文章
- python笔记07-----打包模块(shutil,zipfile,tarfile)
- @Override 注解compiler1.5和compiler1.6不同
- mysql数据库数据监测
- Java 和 JSP 实现网站访问量统计 (刷新过滤)
- Codeforces 960G. Bandit Blues
- Linux 命令 ";cp"; 代码实现简介
- java linux ssh jar
- c#中的out和ref
- SQL Server提取字段中的所有数字
- Vertica示例数据库安装