Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom UItableView not displaying correctly on ios8

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

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

Code used in 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;

Thanks !

like image 264
GondyB Avatar asked Jun 08 '14 20:06

GondyB


1 Answers

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
}
like image 157
mongeta Avatar answered Oct 17 '22 19:10

mongeta