I recently updated to the latest version of Xcode and now i am witnessing some weird behaviour with cell heights in my table. Using iOS7.0 in the simulator and devices was fine but after updating to iOS7.1 the issue is occurring. The issue was NOT occurring on devices with iOS7.1. There has been no code changes after the update.
Essentially, the cells render with correct height initially. The cell will completely disappear from the view when scrolling down, but when it re-appears after scrolling back up, the height has changed by about 20px. The real weird part is when scrolling DOWN again, near the bottom of the view, the cell will change height to the correct assigned height. It will literally jump 20px (approximately) while scrolling.
The code for the cell height is as follows. There is no other code within the view controller that accesses/edit the cells height.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
CGRect frame = cell.frame;
return frame.size.height;
}
Has anyone else experienced this, i have googled pretty hard on this but have come up empty handed. I really need to solve this as my client needs the app uploaded ASAP. hopefully it all makes sense.
EDIT 1: Code
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *simpleTableIdentifier;
NSLog(@"index %d", indexPath.row);
if (indexPath.row == (rowCount -1)){
simpleTableIdentifier = @"moreCellAuto";
}else{
simpleTableIdentifier = @"homeCell";
homeReel = [searchResults objectAtIndex:indexPath.row];
//NSLog(@"crash");
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if([simpleTableIdentifier isEqualToString:@"homeCell"]){
[vidIndex addObject:[homeReel objectForKey:@"VID"]];
[refIndex addObject:[homeReel objectForKey:@"ref"]];
[likeIndex addObject:[homeReel objectForKey:@"likes"]];
[userIndex addObject:[homeReel objectForKey:@"UID"]];
[urlIndex addObject:[homeReel objectForKey:@"URL"]];
[siteIndex addObject:[homeReel objectForKey:@"site"]];
if((NSNull *)[homeReel objectForKey:@"thumb"] != [NSNull null]){
[thumbIndex addObject:[homeReel objectForKey:@"thumb"]];
}else {
[thumbIndex addObject:@""];
}
NSString* title = [homeReel objectForKey:@"title"];
NSString* URL = [homeReel objectForKey:@"ref"];
NSString* postdate = [homeReel objectForKey:@"postdate"];
NSString* userName = [homeReel objectForKey:@"username"];
NSString* likes =[homeReel objectForKey:@"likes"];
NSString* commentsCount =[homeReel objectForKey:@"comment_count"];
NSString* userSub = [homeReel objectForKey:@"userSub"];
NSString* reposts = [homeReel objectForKey:@"reposts"];
NSString* isFeat = [homeReel objectForKey:@"is_featured"];
NSString* type = [homeReel objectForKey:@"type"];
NSString* watchType = [homeReel objectForKey:@"watchType"];
NSString* imageName = [homeReel objectForKey:@"image"];
UILabel *postedBy = (UILabel *)[cell viewWithTag:165];
NSString *postedByText;
if([type isEqualToString:@"featured"]){
postedByText = @"Vindl featured video";
} else {
if([displayType isEqualToString:@"latest"]){
postedByText = [NSString stringWithFormat:@"Posted by %@ Watched by %@", userName, userSub];
} else if ([displayType isEqualToString:@"friend"]){
if (watchType != [NSNull null]){
if([watchType isEqualToString:@"l"]){
postedByText = [NSString stringWithFormat:@"Posted by %@ Liked by %@", userName, userSub];
}else if([watchType isEqualToString:@"c"]){
postedByText = [NSString stringWithFormat:@"Posted by %@ Commented on by %@", userName, userSub];
}
}
} else {
postedByText = [NSString stringWithFormat:@"Posted by %@", userName];
}
}
postedBy.text = postedByText;
postedBy.layer.shadowColor = [[UIColor blackColor] CGColor];
postedBy.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
postedBy.layer.shadowOpacity = 1.0f;
postedBy.layer.shadowRadius = 1.0f;
UILabel *labelPosted = (UILabel *)[cell viewWithTag:101];
labelPosted.layer.shadowColor = [[UIColor blackColor] CGColor];
labelPosted.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
labelPosted.layer.shadowOpacity =1.0f;
labelPosted.layer.shadowRadius = 1.0f;
labelPosted.text = [adVC makeDate:postdate];
UILabel *labelTitle = (UILabel *)[cell viewWithTag:100];
labelTitle.text = title;
labelTitle.layer.shadowColor = [[UIColor blackColor] CGColor];
labelTitle.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
labelTitle.layer.shadowOpacity =1.0f;
labelTitle.layer.shadowRadius = 1.0f;
UILabel *labelLikes = (UILabel *)[cell viewWithTag:103];
if([likes isEqualToString:@"1"]){
labelLikes.text = [NSString stringWithFormat:@"%@ Like", likes];
}else{
labelLikes.text = [NSString stringWithFormat:@"%@ Likes", likes];
}
labelLikes.layer.shadowColor = [[UIColor blackColor] CGColor];
labelLikes.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
labelLikes.layer.shadowOpacity =1.0f;
labelLikes.layer.shadowRadius = 1.0f;
UILabel *labelComCount = (UILabel *)[cell viewWithTag:104];
if([commentsCount isEqualToString:@"1"]){
labelComCount.text = [NSString stringWithFormat:@"%@ Comment", commentsCount];
}else{
labelComCount.text = [NSString stringWithFormat:@"%@ Comments", commentsCount];
}
labelComCount.layer.shadowColor = [[UIColor blackColor] CGColor];
labelComCount.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
labelComCount.layer.shadowOpacity =1.0f;
labelComCount.layer.shadowRadius = 1.0f;
UILabel *labelReposts = (UILabel *)[cell viewWithTag:106];
if([reposts isEqualToString:@"1"]){
labelReposts.text = [NSString stringWithFormat:@"%@ Repost", reposts];
}else{
labelReposts.text = [NSString stringWithFormat:@"%@ Reposts", reposts];
}
labelReposts.layer.shadowColor = [[UIColor blackColor] CGColor];
labelReposts.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
labelReposts.layer.shadowOpacity =1.0f;
labelReposts.layer.shadowRadius = 1.0f;
UIButton *buttonCom = (UIButton *)[cell viewWithTag:111];
[buttonCom addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
//VID PREVIEW IMAGES
NSString *identifierV = URL;
UIImageView *cellImg = (UIImageView *)[cell viewWithTag:144];
if ([cachedImagesVid objectForKey:identifierV] != nil){
cellImg.image = [cachedImagesVid valueForKey:identifierV];
} else {
char const * s = [identifierV UTF8String];
dispatch_queue_t queue = dispatch_queue_create(s, 0);
dispatch_async(queue, ^{
NSString *urlVid = [thumbIndex objectAtIndex:indexPath.row];
UIImage *imgVid = nil;
NSData *dataVid = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:urlVid]];
imgVid = [[UIImage alloc] initWithData:dataVid];
dispatch_async(dispatch_get_main_queue(), ^{
[cachedImagesVid setValue:imgVid forKey:identifierV];
cellImg.image = [cachedImagesVid valueForKey:identifierV];
});
});
}
//USER IMAGES
UIImageView *profileImage = (UIImageView *)[cell viewWithTag:112];
if([type isEqualToString:@"featured"]){
profileImage.image = [UIImage imageNamed:@"Featured-icon.png"];
} else {
NSString *identifier = userName;
if ([cachedImages objectForKey:identifier] != nil){
profileImage.image = [cachedImages valueForKey:identifier];
} else {
char const * s = [identifier UTF8String];
dispatch_queue_t queue = dispatch_queue_create(s, 0);
dispatch_async(queue, ^{
NSString *url = [NSString stringWithFormat:@"http://vindl.com/profiles/%@", imageName];
UIImage *img = nil;
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
img = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
[cachedImages setValue:img forKey:identifier];
profileImage.image = [cachedImages valueForKey:identifier];
});
});
}
}
UIView *bView1 = (UIView *)[cell viewWithTag:130];
bView1.layer.cornerRadius = 3;
bView1.layer.masksToBounds = YES;
UIView *bView2 = (UIView *)[cell viewWithTag:131];
bView2.layer.cornerRadius = 3;
bView2.layer.masksToBounds = YES;
UIView *bView3 = (UIView *)[cell viewWithTag:132];
bView3.layer.cornerRadius = 3;
bView3.layer.masksToBounds = YES;
UIView *bView4 = (UIView *)[cell viewWithTag:133];
bView4.layer.cornerRadius = 3;
bView4.layer.masksToBounds = YES;
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[actInd stopAnimating];
return cell;
}