Objective-C stringWithFormat 缺少参数?
当我运行此代码时:
- (NSString *)description{
return [NSString stringWithFormat:@"(FROG idle:%i animating:%i rect:%@ position:%@ tongue:%@)",
self.idleTime,
self.animating,
NSStringFromCGRect(self.rect),
NSStringFromCGPoint(self.position),
tongue
];
}
我得到以下输出:
(FROG idle:0 animating:0 rect:(null) position:{{1,2}{3,4}} tongue:{5,6})
这是错误的,因为它似乎跳过了 rect 格式字符串并将所有内容都替换为 1。所以空闲和动画是我所期望的,然后跳过 rect,但将 NSStringFromCGRect(self.rect) 的结果放入位置,然后将位置的结果推送到舌头,然后根本不显示舌头。
我不知所措。
When I run this code:
- (NSString *)description{
return [NSString stringWithFormat:@"(FROG idle:%i animating:%i rect:%@ position:%@ tongue:%@)",
self.idleTime,
self.animating,
NSStringFromCGRect(self.rect),
NSStringFromCGPoint(self.position),
tongue
];
}
I get the following output:
(FROG idle:0 animating:0 rect:(null) position:{{1,2}{3,4}} tongue:{5,6})
This is wrong because it seems to be skipping the rect format string and placing everything displaced by one. So idle and animating are what I expect, then rect is skipped, but the result from NSStringFromCGRect(self.rect) is placed into position, then the result for position is pushed to tongue, then tongue is not displayed at all.
I'm at a loss.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有idleTime 和animating 的声明,我无法判断,但是其中一个或两个可能是 %i 说明符的错误类型。也许idleTime是一个double(NSTimeInterval)?
根据它们的实际类型,您可以将它们转换为 int:
I can't tell without the declarations for idleTime and animating, but one or both of this is probably the wrong type for the %i specifier. Perhaps idleTime is a double (NSTimeInterval)?
Depending on what their actual types are, you could convert them to int:
self.rect 不能是有效的 CGRect。你确定你不是说 self.frame 吗?
self.rect must not be a valid CGRect. Are you sure you don't mean self.frame?