2

我无法定义一个常数。

这是我的定义:

const float tableOffset = 200;

这是我尝试使用它的方式(见最后):

[self.voteTbl setFrame:CGRectMake(0,200,self.view.frame.size.width, self.view.frame.size.height - bottomBar.frame.size.height - tableOffset)];

但是,这不起作用,实际上设置了正确的高度。此代码确实有效:

[self.voteTbl setFrame:CGRectMake(0,200,self.view.frame.size.width, self.view.frame.size.height - bottomBar.frame.size.height - 200)];

我试过切换到 int 没有运气。编译器不给出警告或错误。

4

1 回答 1

0

当您在 const 声明中尝试“200.0f”时会发生什么?

另外,为了超级精确,使用“CGFloat”而不是“float”。一般来说,当我需要使用浮点数(或 CGFloats)时,我会在数字末尾添加一个“f”字符,以向编译器表明是的,这确实是一个浮点数。

于 2013-08-25T01:39:16.723 回答