Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa touch 将CGPoint转换为字符串时出现问题_Cocoa Touch_String_Nsstring_Cgpoint - Fatal编程技术网

Cocoa touch 将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

我在将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];
我得到输出,但它只是说“坐标(null)”,我不明白为什么


谢谢

您的格式字符串使用了一个只适用于objective-C对象的
%@
。看起来您试图打印的不是一个而是两个值(x和y),这两个值都是浮点数。试试这个:

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