[英]Really really basic Obj-C question about passing instance variables
嗨,您好,對於這樣一個愚蠢的問題,我正在根據分段控件的索引來更改變量值,但是想在隨后的計算中使用該變量; 確定這與變量作用域有關嗎?
- (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);
}
幫助非常感謝!
- (IBAction)calculate:(UIButton *)button {
float s = 0;
if( [sSeg selectedSegmentIndex]==1){
s=0.5;
NSLog(@"s=%f", s);
}
else if ([sSeg selectedSegmentIndex]==0)
{
s=1;
NSLog(@"s=%f", s);
}
NSLog(@”s now = %f”, s);
}
是的,它的范圍-變量僅在大括號內可見。
- (IBAction)calculate:(UIButton *)button {
float s;
if( [sSeg selectedSegmentIndex]==1){
s=0.5;
NSLog(@"s=%f", s);
}
else if ([sSeg selectedSegmentIndex]==0)
{
s=1;
NSLog(@"s=%f", s);
}
NSLog(@”s now = %f”, s);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.