代码写Button遇到问题
2012-06-25 22:03
288 查看
夜晚本来像用代码写一个Button按钮,但是出现问题:开始是这样创建的
按照这个看似没问题,但是在模拟器上运行的时候,Button并没有出现,用模拟器分析显示Value stored to 'writeButton' during its initialization is never read(值存储到“writeButton”在其初始化是从来没有读过)
这样写在模拟器上也没有显示Button
当这样写的时候才出现Button在模拟器视图上,于是啄么着是Button初始化frame时候,没有确定Button类型(此处是UIButtonTypeRoundedRect),
但是由product----》Analyze 又出现Value stored to 'writeButton' during its initialization is never read
再次修改
难道是因为不需要初始化吗? 这个问题暂时不能理解
- (void)viewDidLoad { [super viewDidLoad];
//初始化Button的位置大小 UIButton *writeButton = [[UIButton alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 50.0f, 30.0f)]; //设置BUtton的形状,此处为圆角按钮 writeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //设置Button名字,和他的状态,此处是一般的状态 [writeButton setTitle:@"代码按钮" forState:UIControlStateNormal]; //Button背景色 writeButton.backgroundColor = [UIColor redColor]; //Button的触摸事件 [writeButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside]; //把Button添加到视图之上 [self.view addSubview:writeButton]; }
按照这个看似没问题,但是在模拟器上运行的时候,Button并没有出现,用模拟器分析显示Value stored to 'writeButton' during its initialization is never read(值存储到“writeButton”在其初始化是从来没有读过)
- (void)viewDidLoad { [super viewDidLoad];
UIButton *writeButton = [[UIButton alloc] init];
CGRect frame = CGRectMake(100.0f, 100.0f, 50.0f, 30.0f);
writeButton.frame= frame;
writeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[writeButton setTitle:@"代码按钮" forState:UIControlStateNormal];
writeButton.backgroundColor = [UIColor redColor];
[writeButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:writeButton];
}
这样写在模拟器上也没有显示Button
- (void)viewDidLoad { [super viewDidLoad];
UIButton *writeButton = [[UIButton alloc] init];
CGRect frame = CGRectMake(100.0f, 100.0f, 100.0f, 30.0f);
writeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
writeButton.frame= frame;
[writeButton setTitle:@"代码按钮" forState:UIControlStateNormal];
writeButton.backgroundColor = [UIColor redColor];
[writeButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:writeButton];
}
当这样写的时候才出现Button在模拟器视图上,于是啄么着是Button初始化frame时候,没有确定Button类型(此处是UIButtonTypeRoundedRect),
但是由product----》Analyze 又出现Value stored to 'writeButton' during its initialization is never read
再次修改
- (void)viewDidLoad { [super viewDidLoad];
CGRect frame = CGRectMake(100.0f, 100.0f, 100.0f, 30.0f);
UIButton *writeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// writeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
writeButton.frame= frame;
[writeButton setTitle:@"代码按钮" forState:UIControlStateNormal];
writeButton.backgroundColor = [UIColor redColor];
[writeButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:writeButton];
}
难道是因为不需要初始化吗? 这个问题暂时不能理解
相关文章推荐
- 代码写Button遇到问题
- vc6代码转到vc2010遇到的问题
- 代码调试遇到的问题
- https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题
- 新路程------编译海思代码遇到的问题
- bootstrap 事件shown.bs.modal用于监听并执行你自己的代码【写hostmanger关联部门遇到的问题及解决方法】
- 看代码中遇到的问题
- 【记录】使用eclipse遇到的问题一:eclipse中按空格/Tab键错误触发代码补全
- 自行编写代码解决 WTForm 无纯 Button 按钮的问题——button篇
- 显著性检测代码调试所遇到的问题
- 使用Pycharm 社区版配合anaconda进行代码编写遇到的一些小问题汇总
- 编写android jni代码时遇到的问题
- [SVN技巧]代码提交中遇到的两个问题及其解决方案
- idea中git提交代码遇到的问题(反复输入密码,用户名显示不正常)
- 当button按钮放入form表单进行ajax提交遇到的诡异问题
- 基于51单片机的计算器写代码遇到的问题及解决办法
- 我在“代码访问安全”遇到的问题,并得到了解决!
- matllab转为C代码遇到的问题:找不到VS的编译器
- 学习Opencv中文版--例2--10,书上的代码有点问题,现在把遇到的问题及解决方案作总结
- 关于编译4+2版本遇到的不是代码的问题和添加launcher以及svn上传问题