我在定义常量时遇到麻烦。
这是我的定义方式:
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。编译器不给出警告或错误。
最佳答案
当您在const声明中尝试“200.0f”时会发生什么?
另外,为了精确起见,请使用“CGFloat”而不是“float”。通常,对于需要使用浮点数(或CGFloats)的时间,我在数字的末尾添加一个“f”字符,以向编译器表示是的,这确实是一个浮点数。
关于ios - 定义一个常数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18424597/