2010-06-18 22 views
4

我一直在將CGPoint轉換爲字符串時遇到問題。我嘗試了各種方法,但這似乎是最有前途的,但它仍然無法工作。有什麼建議麼?將CGPoint轉換爲字符串的問題

這裏是我的代碼:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    coord = [touch locationInView:touch.view]; 
    viewcoord.text = [NSString stringWithFormat:@"coordinates %@", coord.x, coord.y]; 

我得到的輸出,但它只是說, 「座標(空)」 我不明白爲什麼...

感謝

回答

1

您的格式字符串使用僅適用於Objective-C對象的%@。你看起來像你試圖打印不是一個,而是兩個值(x和y),這兩個值都是浮動值。試試這個:

viewcoord.text = [NSString stringWithFormat:@"coordinates %f, %f", coord.x, coord.y]; 
14
viewcoord.text = [NSString stringWithFormat:@"coordinates %@", NSStringFromCGPoint(coord)];