自定义UItableView无法在ios8上正确显示 [英] custom UItableView not displaying correctly on ios8

查看:65
本文介绍了自定义UItableView无法在ios8上正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个自定义 UITableViewCell ,当我显示它时,我得到了这个结果(我在iPhone 5上运行xcode 6和iOS 8 beta 1.)

I made a custom UITableViewCell and when I display it, i have this result (I'm running xcode 6 and iOS 8 beta 1 on an iPhone 5.)

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

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

And when I rotate my device, then rotate back to portrait, everything becomes correct.

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

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

Note that when I was using xcode 5 to compile my app, I had no problems.

中使用的代码cellForRowAtIndexPath:

BGTCoursCell1 *cell = (BGTCoursCell1 *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSArray  *nib = [[NSBundle  mainBundle] loadNibNamed:@"BGTCoursCell1" owner:self options:nil];
cell = [nib objectAtIndex:0];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
NSLocale *locale = [NSLocale currentLocale];
[dateFormatter setLocale:locale];

if (indexPath.section == 0)
{
   BGTCours *cours = [[currentDay coursMatin] objectAtIndex:indexPath.row];
    cell.matiereLabel.text = [cours matiere];
    cell.salleLabel.text = [cours salle];
    cell.heureLabel.text = [NSString stringWithFormat:@"De %@ à %@", [dateFormatter stringFromDate:[cours beginDate]], [dateFormatter stringFromDate:[cours endDate]]];
}
else
{
   BGTCours *cours = [[currentDay coursAprem] objectAtIndex:indexPath.row];
    cell.matiereLabel.text = [cours matiere];
    cell.salleLabel.text = [cours salle];
    cell.heureLabel.text = [NSString stringWithFormat:@"De %@ à %@", [dateFormatter stringFromDate:[cours beginDate]], [dateFormatter stringFromDate:[cours endDate]]];
}
return cell;

谢谢!

推荐答案

您需要从 tableView:heightForRowAtIndexPath:返回 CGFloat 。如果从同一方法返回浮点数,则会出现错误:

You need to return a CGFloat from the tableView:heightForRowAtIndexPath: . The error you are seeing will appear if you return a float from the same method:

//causes the bug
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    //...
}

//fixes the bug
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return tableView.rowHeight; // whatever
}

这篇关于自定义UItableView无法在ios8上正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆