可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 !
回答1:
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 }
回答2:
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.
回答3:
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.
回答4:
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;
回答5:
i had a slightly similar problem and fixed it by using cell.clipsToBounds = YES