NSString concat不适用于设备

时间:2015-06-03 11:18:46

标签: ios objective-c nsstring concatenation

我遇到了一个小小的挑战。我正在使用以下代码来连接NSString。在控制台上输出很好,在设备上它不起作用。我似乎无法弄清楚我错过了什么。

- (void)loadContent {
    getHTML = @"leap";
    NSLog(@"getHTML start: %@", getHTML);
    int showLeap = selectedLeap +1;
    NSString *leapString = [NSString stringWithFormat:@"%d", showLeap];

    if (showLeap<10) {
        getHTML = [getHTML stringByAppendingString:@"0"];
    }

    getHTML = [getHTML stringByAppendingString:leapString];
    getHTML = [getHTML stringByAppendingString:selectedMenu];
    NSLog(@"getHTML complete: %@", getHTML);

在模拟器上,输出为:

2015-06-03 12:11:57.619 iOS_TWW_EVOLUTION[917:582733] getHTML start: leap
2015-06-03 12:11:57.621 iOS_TWW_EVOLUTION[917:582733] getHTML complete: leap01_summary

在设备上,输出为:

2015-06-03 12:15:40.341 iOS_TWW_EVOLUTION[917:582733] getHTML start: leap
2015-06-03 12:15:40.346 iOS_TWW_EVOLUTION[917:582733] getHTML complete: getHTML complete: 

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 [NSString stringByAppendingString ...]方法在设备上保持返回nil有点奇怪。这是我使用[NSString stringWithFormat ...]方法的解决方案;

while (*p) {