UITableView设置heightForRowAt是CGFloat.leastNormalMagnitude,但它崩溃了

时间:2017-05-04 08:27:10

标签: ios swift uitableview

我的tableView设置

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
   if indexPath == kFirstCellIndexPath && category == .overtime {
     return CGFloat.leastNormalMagnitude // it will crash
     return 0  // it will not crash
   } else {
     return UITableViewAutomaticDimension
   }
}

然后我设置单元格的高度

<template>

     <multiselect v-model="value"
        :options="options"
        :multiple="true"
        :close-on-select="false"
        :clear-on-select="false"
        :hide-selected="true"
        placeholder="Pick some"
        label="name"
        track-by="name">
      </multiselect>

</template>


<script>

import Multiselect from 'vue-multiselect'

export default {
components: {
  Multiselect
},
data () {
  return {
    value: [
      { name: 'Vue.js', language: 'JavaScript' }
    ],
    options: [
      { name: 'Vue.js', language: 'JavaScript' },
      { name: 'Adonis', language: 'JavaScript' },
      { name: 'Rails', language: 'Ruby' },
      { name: 'Sinatra', language: 'Ruby' },
      { name: 'Laravel', language: 'PHP' },
      { name: 'Phoenix', language: 'Elixir' }
    ]
  }
}
}

</script>

当我重新加载tableView时,它崩溃了,为什么?

1 个答案:

答案 0 :(得分:0)

替换此行

    return CGFloat.leastNormalMagnitude 

  return  CGFloat(FLT_MIN)

在表格视图的heightForRowAtIndexpath方法中。