我做了一个自定义的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
- }