字符串和数组

时间:2011-05-13 12:14:51

标签: iphone objective-c cocoa-touch

NSString *depositOverTotalRwy = [NSString stringWithFormat:@"%@", [deposit text]];
NSArray *components = [depositOverTotalRwy
                       componentsSeparatedByString:@"/"];
NSString *firstThird = [components objectAtIndex:0];
if ([firstThird isEqualToString: @"1"]) {
    NSLog(@"wet");
}
if ([firstThird isEqualToString:@"2"]) {
    NSLog(@"snow");
}
if ([firstThird isEqualToString:@"3"]) {
    NSLog(@"ice");
    }
NSString *secThird = [components objectAtIndex:1];
if ([secThird isEqualToString: @"1"]) {
    NSLog(@"wet");
}
if ([secThird isEqualToString:@"2"]) {
    NSLog(@"snow");
}
if ([secThird isEqualToString:@"3"]) {
    NSLog(@"ice");
}

NSString *thirdThird = [components objectAtIndex:2];

if ([thirdThird isEqualToString: @"1"]) {
    NSLog(@"wet");
}
if ([thirdThird isEqualToString:@"2"]) {
    NSLog(@"snow");
}
if ([thirdThird isEqualToString:@"3"]) {
    NSLog(@"ice");
}
dep.text = [NSString stringWithFormat:@"%@ over %@ over %@", firstThird, secThird, thirdThird];
你好,伙计们, 我有个问题。当我设置标签(dep.text)时,我得到的数字而不是湿,雪或冰。它在控制台(NSlog)中工作。 我知道它必须是逻辑中的一些错误,但我无法找到它。提前谢谢。

2 个答案:

答案 0 :(得分:3)

而不是NSLog(@"snow");分配firstThird=@"snow"

答案 1 :(得分:0)

它在我看来,因为组件中的对象是@“1”,@“2”或@“3”。

dep.text反映了

如果dep.text类似于你想要的,你需要设置字符串,比如 -

thirdThird = @"wet";

thirdThird = @"snow";

thirdThird = @"ice";

当然条件

}