自定义UItableView无法在ios8上正确显示

前端之家收集整理的这篇文章主要介绍了自定义UItableView无法在ios8上正确显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我做了一个自定义的UITableViewCell,当我显示它时,我有这个结果(我在iPhone 5上运行 xcode 6和iOS 8 beta 1.)

http://imgur.com/2MyT0mF,Nx1o4bl#0

当我旋转我的设备,然后旋转回肖像,一切都变得正确.

http://imgur.com/2MyT0mF,Nx1o4bl#1

请注意,当我使用xcode 5编译我的应用程序时,我没有遇到任何问题.

cellForRowAtIndexPath中使用的代码

  1. BGTCoursCell1 *cell = (BGTCoursCell1 *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
  2. NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BGTCoursCell1" owner:self options:nil];
  3. cell = [nib objectAtIndex:0];
  4. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  5. [dateFormatter setDateFormat:@"HH:mm"];
  6. NSLocale *locale = [NSLocale currentLocale];
  7. [dateFormatter setLocale:locale];
  8.  
  9. if (indexPath.section == 0)
  10. {
  11. BGTCours *cours = [[currentDay coursMatin] objectAtIndex:indexPath.row];
  12. cell.matiereLabel.text = [cours matiere];
  13. cell.salleLabel.text = [cours salle];
  14. cell.heureLabel.text = [NSString stringWithFormat:@"De %@ à %@",[dateFormatter stringFromDate:[cours beginDate]],[dateFormatter stringFromDate:[cours endDate]]];
  15. }
  16. else
  17. {
  18. BGTCours *cours = [[currentDay coursAprem] objectAtIndex:indexPath.row];
  19. cell.matiereLabel.text = [cours matiere];
  20. cell.salleLabel.text = [cours salle];
  21. cell.heureLabel.text = [NSString stringWithFormat:@"De %@ à %@",[dateFormatter stringFromDate:[cours endDate]]];
  22. }
  23. return cell;

谢谢 !

解决方法

您需要从tableView:heightForRowAtIndexPath:返回一个CGFloat.如果从同一方法返回一个浮点数,则会出现您看到的错误
  1. //causes the bug
  2. -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  3. //...
  4. }
  5.  
  6. //fixes the bug
  7. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  8. return tableView.rowHeight; // whatever
  9. }

猜你在找的iOS相关文章