我试图将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 }