在Swift中将Int更改为CGFloat以返回heightForRowAtIndexPath tableview函数 [英] Changing an Int to a CGFloat in Swift to return heightForRowAtIndexPath tableview function
本文介绍了在Swift中将Int更改为CGFloat以返回heightForRowAtIndexPath tableview函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确信我错过了一些非常简单的东西,但我无法让它发挥作用。
如果他们遇到同样的问题,我会尝试更好地解释我正在做些什么来帮助他人。
<这是我的函数:
func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat {
返回(计数* 40 + 75)为CGFloat
}
上述功能不起作用。感谢我收到的帮助,我发现这是这样做的方法:
func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat {
返回CGFloat(计数* 40 + 75)
}
谢谢!
解决方案
是的,很简单:
让i = 123 //一个Int
让f = CGFloat(i)//一个CGFloat
如果你命令点击 CGFloat
那么你会看到它的所有初始化器:
init(_ value:Float)
init(_ value:Double)
// ......还有更多,最后:
init( _ value:UInt)
init(_ value:Int)
I am sure that I am missing something really simple, but I just can't get it to work.
I will try to explain better what I am doing to try to help others if they have this same issue.
This was my function:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return (count * 40 + 75) as CGFloat
}
The above function doesn't work. Thanks to the help I received, I found that this is the way to do it:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return CGFloat(count * 40 + 75)
}
Thanks!
解决方案
Yes, it is simple:
let i = 123 // an Int
let f = CGFloat(i) // a CGFloat
If you command-click on CGFloat
then you'll see all its initializers:
init(_ value: Float)
init(_ value: Double)
// ... many more, and finally:
init(_ value: UInt)
init(_ value: Int)
这篇关于在Swift中将Int更改为CGFloat以返回heightForRowAtIndexPath tableview函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文