自定义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中使用的代码

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 endDate]]];
}
return cell;

谢谢 !

解决方法

您需要从tableView:heightForRowAtIndexPath:返回一个CGFloat.如果从同一方法返回一个浮点数,则会出现您看到的错误
//causes the bug
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    //...
}

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...