自定义的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:使用的代码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 。 如果您从相同的方法返回一个浮点数,您将看到错误:

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

这个问题有一个可接受的答案,但我有同样的问题,这是不被接受的答案,这告诉我们改变float CGFloat固定的问题。

我发现基于表rowHeight代码也可能有这个问题。 在iOS8中,重要的是查看estimatedRowHeight而不仅仅是rowHeight

正如我在编程生成的UITableView使用这些variables,修复这些variables解决了这个问题。

我可能会晚了一点,但我今天(2014年6月26日)遇到了与iOS 8 beta 2和xCode 6 beta 2完全相同的问题,我看他们还没有修复这个bug。

还有另一个与xCode 6testing版的错误,那就是我的应用程序不能正确地请求GPS位置 – 它根本不会要求许可。 这也是通过切换回xCode 5来解决的。我认为目前使用xCode 5来构build和testing你的应用程序是更可行的。

尝试重用单元格,例如,更改:

 BGTCoursCell1 *cell = (BGTCoursCell1 *)[tableView dequeueReusableCellWithIdentifier:@"Cell"]; NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BGTCoursCell1" owner:self options:nil]; cell = [nib objectAtIndex:0]; 

 static NSString *CellIdentifier = @"Cell"; static NSString *CellNib = @"BGTCoursCell1"; BGTCoursCell1 *cell = (BGTCoursCell1 *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if( cell == nil ) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; cell = [nib objectAtIndex:0]; } ... return cell; 

我有一个类似的问题,并通过使用cell.clipsToBounds = YES修复它