1

単純だがイライラする問題があります。

アプリに次の行があります。

[super setText:[[[NSString alloc] initWithFormat:@"%i" arguments:arg] autorelease]];

その行はサードパーティのライブラリからのものだったので、警告を取り除いて適切に機能させようとしました。とにかく、どうすればこの警告を修正できますか?

ありがとう!

完全な方法:

- (void)timerLoop:(NSTimer *)aTimer {
    //update current value
    currentTextNumber += currentStep;

    //check if the timer needs to be disabled
    if ( (currentStep >= 0 && currentTextNumber >= textNumber) || (currentStep < 0 && currentTextNumber <= textNumber) ) {
        currentTextNumber = textNumber;
        [self.timer invalidate];
    }

    //update the label using the specified format
    int value = (int)currentTextNumber;
    int *arg = (int *)malloc(sizeof(int));
    memcpy(arg, &value, sizeof(int));
    //call the superclass to show the appropriate text
    [super setText:[[[NSString alloc] initWithFormat:@"%i" arguments:arg] autorelease]];
    free(arg);
}
4

1 に答える 1

4

次のように変更しないでください:

NSString *text = [NSString stringWithFormat:@"%i", arg];
[super setText:text];

これはarg、 のタイプがint.

実際に可変引数リストの であるinitWithFormat:arguments:場合にのみ使用します。argva_list

更新:投稿した更新されたコードに基づいて、次のことができます。

- (void)timerLoop:(NSTimer *)aTimer {
    //update current value
    currentTextNumber += currentStep;

    //check if the timer needs to be disabled
    if ( (currentStep >= 0 && currentTextNumber >= textNumber) || (currentStep < 0 && currentTextNumber <= textNumber) ) {
        currentTextNumber = textNumber;
        [self.timer invalidate];
    }

    //update the label using the specified format
    int value = (int)currentTextNumber;
    [super setText:[NSString stringWithFormat:@"%i", value]];
}
于 2013-04-06T02:30:27.263 に答える