Cocoa touch 将CGPoint转换为字符串时出现问题
我在将CGPoint转换为字符串时遇到问题。我尝试过各种方法,但这似乎是最有希望的,但仍然不起作用。有什么建议吗 这是我的密码:Cocoa touch 将CGPoint转换为字符串时出现问题,cocoa-touch,string,nsstring,cgpoint,Cocoa Touch,String,Nsstring,Cgpoint,我在将CGPoint转换为字符串时遇到问题。我尝试过各种方法,但这似乎是最有希望的,但仍然不起作用。有什么建议吗 这是我的密码: -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; coord = [touch locationInView:touch.view]; viewcoord.tex
-(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];
我得到输出,但它只是说“坐标(null)”,我不明白为什么
谢谢您的格式字符串使用了一个只适用于objective-C对象的
%@
。看起来您试图打印的不是一个而是两个值(x和y),这两个值都是浮点数。试试这个:
viewcoord.text = [NSString stringWithFormat:@"coordinates %f, %f", coord.x, coord.y];
viewcoord.text = [NSString stringWithFormat:@"coordinates %@", NSStringFromCGPoint(coord)];