微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xcode – swift UITableView设置rowHeight

我试图将tableView中的每一行的高度设置为相应单元格的高度,代码如下:

override func tableView(tableView: UITableView!,heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
      var cell = tableView.cellForRowAtIndexPath(indexPath)
      return cell.frame.height
}

在初始化var cell时我得到这个错误:

Thread 1:EXC_BAD_ACCESS(code=2,address=0x306d2c)

解决方法

为了设置行高,有单独的方法:

对于Swift 3

func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat
{
    return 100.0;//Choose your custom row height
}

旧的Swift使用

func tableView(tableView: UITableView,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
{
    return 100.0;//Choose your custom row height
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐