2010-06-18 20 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)];