2

タッチの持続時間を記録し、画面に表示した後にどのように印刷しますか?

ここに画像の説明を入力

上記のコードは次のとおりです。

// add this ivar to your view controller
NSTimeInterval lastTouch;
int textTime;

// assign the time interval in touchesBegan:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{
    lastTouch = [event timestamp];
}


// calculate and print interval in touchesEnded:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
{
    NSTimeInterval touchBeginEndInterval = [event timestamp] - lastTouch;
    textTime = touchBeginEndInterval;
    NSLog(@"touchBeginEndInterval %f", touchBeginEndInterval);
    dynLabel.text = textTime;
}
4

1 に答える 1

1
dynLabel.text = textTime;

ラベルのtextプロパティにはNSString*が必要ですがNSTimeInterval、番号を付けています。それがエラーの意味です。NSString の-stringWithFormat:メソッドなどを使用して文字列を作成します。

于 2012-10-05T00:20:42.983 に答える