关于传递实例变量的非常非常基本的 Obj-C 问题
嗨,很抱歉问了这么愚蠢的问题 我正在根据分段控件的索引更改变量值,但随后希望在接下来的计算中使用该变量;我确定这与变量作用域有关吗?
- (IBAction)calculate:(UIButton *)button {
if( [sSeg selectedSegmentIndex]==1){
float s=0.5;
NSLog(@"s=%f", s);
}
else if ([sSeg selectedSegmentIndex]==0)
{
float s=1;
NSLog(@"s=%f", s);
}
NSLog(@”s now = %f”, s);
!
非常感谢帮助
Hi sorry about such a dumb question
I am changing a variable value depending on the index of a segmented control but then want to use this variable in a calculation that follows; am sure this has something to do with variable scoping?
- (IBAction)calculate:(UIButton *)button {
if( [sSeg selectedSegmentIndex]==1){
float s=0.5;
NSLog(@"s=%f", s);
}
else if ([sSeg selectedSegmentIndex]==0)
{
float s=1;
NSLog(@"s=%f", s);
}
NSLog(@”s now = %f”, s);
}
Help much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的
,它的范围 - 变量仅在大括号内可见。
}
Yeah, its the scope - a variable is only visible inside your curly brackets.