What causes this error? “CALayer position contains NaN: [240 nan]”

前端 未结 7 1667
星月不相逢
星月不相逢 2020-12-08 00:41

I\'ve seen this happen whenever i rotate a screen that has a UITableView on it. I\'ve found out that it happens inbetween the willRotate and

7条回答
  •  温柔的废话
    2020-12-08 01:06

    I had this problem when i was assumed that:

    tableView:heightForHeaderInSection: returned an NSInteger, but it returns CGFloat...

    changing:

    -(NSInteger)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    

    to

    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    

    fixed my issue.

    Edit:

    At some point I figured out how computers work below the C level, so I thought I would share it... (I will use an register names from x86_64 as I am most familiar with them, ARM would be slightly different but analogous)

    int f(){
              float someFloat=5.0f;
              return someFloat;
           }
    

    results in converting the value of someFloat to an integer type then copying that to a particular register: %rax then calling the return instruction.

    float f(){
              float someFloat=5.0f;
              return someFloat;
           }
    

    results in copying the value of someFloat from its current location to a particular register: %xmm0 then calling the return instruction.

    So if you have the wrong prototype the calling code will expect the value to be in the wrong place, you will end up really returning a garbage value.

提交回复
热议问题