Reputation: 423
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.)
https://i.sstatic.net/9Oswn.png
And when I rotate my device, then rotate back to portrait, everything becomes correct.
https://i.sstatic.net/TlICk.png
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 !
Upvotes: 7
Views: 4746
Reputation: 2301
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
}
Upvotes: 10
Reputation: 6826
This question has an accepted answer, but I have the same problem which was not fixed by the accepted answer which tells us to change float
to CGFloat
.
I found out that people who has code based on table's rowHeight
may have this problem too. In iOS8 it is important to look at estimatedRowHeight
not just rowHeight
.
As I was using these variables in my programmatically generated UITableView
, fixing those variables solved the problem.
Upvotes: 2
Reputation: 558
i had a slightly similar problem and fixed it by using cell.clipsToBounds = YES
Upvotes: 0
Reputation: 453
I might be a bit late to the party but I've encountered exactly same problem with iOS 8 beta 2 and xCode 6 beta 2 today(26-June-2014), I see they still haven't fixed the bug.
There's also another bug with xCode 6 beta, that is my app can no request the GPS location properly - it simply won't ask for the permission. This is also solved by switching back to xCode 5. I think at the moment is more viable to use xCode 5 to build and test your app.
Upvotes: 1
Reputation: 100175
try reusing the cell, like, change:
BGTCoursCell1 *cell = (BGTCoursCell1 *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"BGTCoursCell1" owner:self options:nil];
cell = [nib objectAtIndex:0];
to
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;
Upvotes: 0