大佬教程收集整理的这篇文章主要介绍了iOS – 表格视图单元格,UITextView未正确调整大小,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
码:
-(CGFloat)tableView:(UITableView *)tableView heightForRowATindexPath:(NSIndexPath *)indexPath{ int defaultSize = 0; int height = 0; if(indexPath.section%2==0){ defaultSize = 160; NSMutableDictionary *currentPost = [newsFeedPosts objectATindex:indexPath.section]; NSString *String = [currentPost valueForKey:@"detailsText"]; CGSize StringSize = [String sizeWithFont:[UIFont boldSystemFontOfSize:15] consTrainedToSize:CGSizeMake(320,9999) lineBreakmode:NSLineBreakByWordWrapping]; height = StringSize.height + defaultSize; NSLog(@"String Size Before: %f",StringSize.height); }else{ defaultSize = 270; height = defaultSize; } return height; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier; if(indexPath.section%2==0){ CellIdentifier = @"NewsFeedText"; }else{ CellIdentifier = @"NewsFeedImage"; } NewsFeedCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // Configure the cell... [cell setBACkgroundView:[[NewsFeedCellBACkground alloc] init]]; [cell.bottomcatontainer setClipsToBounds:YES]; [cell.bottomcatontainer.layer setMasksToBounds:YES]; [cell.imagePreview.imageView setContentMode:UIViewContentModeScaleAspectFit]; [cell.bottomcatontainer setFrame:CGRectMake(0,cell.contentView.frame.size.height-30,cell.contentView.frame.size.width,30)]; //Data Object NSMutableDictionary *currentPost = [newsFeedPosts objectATindex:indexPath.section]; //View cell.userImage.image = [UIImage imagenamed:[currentPost valueForKey:@"userImage"]]; cell.userName.text = [currentPost valueForKey:@"userName"]; cell.createdDate.text = [currentPost valueForKey:@"createdDate"]; cell.patientName.text = [currentPost valueForKey:@"patientName"]; cell.detailsText.text = [currentPost valueForKey:@"detailsText"]; [cell.imagePreview setImage:[UIImage imagenamed:[currentPost valueForKey:@"imagePreview"]] forState:UIControlStateNormal]; [cell.viewCase addTarget:self action:@SELEctor(displayCase:) forControlEvents:UIControlEventTouchUpInside]; //Image [cell.imagePreview addTarget:self action:@SELEctor(displayImage:) forControlEvents:UIControlEventTouchUpInside]; //Data cell.viewCase.tag = [[currentPost valueForKey:@"casEID"] intValue]; //Cell Adjustments NSString *String = [currentPost valueForKey:@"detailsText"]; CGSize StringSize = [String sizeWithFont:[UIFont boldSystemFontOfSize:15] consTrainedToSize:CGSizeMake(320,9999) lineBreakmode:NSLineBreakByWordWrapping]; NSLog(@"String Size After: %f",StringSize.height); [cell.detailsText setFrame:CGRectMake(cell.detailsText.frame.origin.x,cell.detailsText.frame.origin.y,cell.detailsText.frame.size.width,StringSize.height+10)]; [cell.detailsText setBACkgroundColor:[UIColor redColor]]; return cell; }
以上是大佬教程为你收集整理的iOS – 表格视图单元格,UITextView未正确调整大小全部内容,希望文章能够帮你解决iOS – 表格视图单元格,UITextView未正确调整大小所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。