将 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];
我得到输出,但它只是说“坐标(空)”,我不明白为什么......
谢谢
I have been having problems with converting a CGPoint to a string. I have tried various methods, but this seems like the most promising but it still won't work. Any suggestions?
Here is my code:
-(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];
I get output but it just says "coordinates (null)" and I don't understand why...
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的格式字符串使用仅适用于 Objective-C 对象的
%@
。您看起来像是在尝试打印不是一个而是两个值(x 和 y),这两个值都是浮点数。试试这个:Your format string uses a
%@
which only applies to objective-C objects. You look like you're trying to print not one but two values (the x and the y), both of which are floats. Try this: