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
}

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...