cell自动换行

#import"HistoryMessageViewController.h"

#import"UITableView+FDTemplateLayoutCell.h"

#import"HistoryMessageCell.h"



#define FONT_SIZE14.0f

#define CELL_CONTENT_WIDTH320.0f

#define CELL_CONTENT_MARGIN10.0f




#define ScreenWidth [UIScreen mainScreen].bounds.size.width

#define ScreenHeight [UIScreen mainScreen].bounds.size.height





#define FONT_NAME @"Heiti SC"

@interfaceHistoryMessageViewController()<UIActionSheetDelegate>



{

NSMutableArray*myCells;// cell数组

}

@property(nonatomic,strong)NSMutableArray*feedEntitySections;

@property(nonatomic,assign)BOOLcellHeightCacheEnabled;

@property(nonatomic,strong)NSArray* tableData;


@end


@implementationHistoryMessageViewController


- (void)viewDidLoad {

[superviewDidLoad];

[selfloadBackItem];

self.title=@"历史评价";

self.tableData=@[

@"中国网3月26日讯据外媒报道,当地时间3月25日,法国总统奥朗德,德国总理默克尔、西班牙首相拉霍伊共同抵达德国之翼航空公司客机的失事地点。报道称,三位国家领导人抵达当地以后,与参加搜救的工作人员在临时指挥中心进行了会面。此外,法、德、西三国领导人在客机坠毁地点附近对在此次空难中的遇难者表示哀悼,并对参与搜救的消防队员表示了感谢。",

@"大量的文物流失,频频的文物破坏已成为中国文物保护工作的常年之痛。中国文物保护立法已经30多年,今天,除了相关部门对文物保护的漠视和不作为,我们剩下的只有那些越来越少的沉默的文物。",

@"当地时间2015年3月25日,乌克兰基辅,在记者、摄影师及一众高官的注视之下,乌克兰警方冲入一场电视转播的内阁会议现场,逮捕乌克兰紧急服务部部长Serhiy Bochkovsky及其副手Vasyl Stoyetsky,两人均被控“高层次”腐败。据乌克兰内政部长表示,被捕的两人涉嫌多付给包括俄罗斯石油巨头卢克石油公司在内的多家公司采购费用。",

@"四川峨眉山景区降近7年来最大雪",

@"萌物:伊犁鼠兔是世界珍稀动物之一。日前,这一天然萌物再次在中国新疆被发现。伊犁鼠兔,生活在天山山脉高寒山区,是中国新疆特有的一个物种。3月23日,实名认证微博“美国国家地理”发布一组有关伊犁鼠兔的照片,因其形象呆萌可爱,长相酷似泰迪,立即引起了众多网友的关注。23日中午,记者电话联系到新疆发现鼠兔第一人,新疆环境保护科学研究院副研究员、新疆生态学会副秘书长李维东,他义务跟踪保护鼠兔三十多年。李维东介绍,美国国家地理微博晒出的这组鼠兔照片,是他去年7月在天山精河县木孜克冰达坂布设红外线触发相机时摄到的。照片中的鼠兔,也是他时隔24年后再次拍摄到的珍贵镜头。"

];

}


- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

}


-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{

return1;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

returnself.tableData.count;

}


-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{

NSString*text = [_tableDataobjectAtIndex:[indexPathrow]];

//

// // CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

//

//// CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];

////

//

// CGSize size =[text boundingRectWithSize:CGSizeMake(305*ScreenWidth/375,ScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15*ScreenWidth/375]} context:nil].size;

//

// CGFloat height = MAX(size.height, 44.0f);

//

// return height + (CELL_CONTENT_MARGIN * 2);

//

// static NSString *customCellIndentifier = @"HistoryMessageCell";

//

// HistoryMessageCell *cell = (HistoryMessageCell *)[tableView dequeueReusableCellWithIdentifier:customCellIndentifier];

//

//

// if(cell == nil){

// NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HistoryMessageCell" owner:self options:nil];

// cell = [nib objectAtIndex:0];

// }

//设置点击没有变色

// cell.selectionStyle = UITableViewCellSelectionStyleNone;

// cell.haolb.text=[self.tableData objectAtIndex:indexPath.row];

// cell.haolb.lineBreakMode = NSLineBreakByWordWrapping;

// cell.haolb.numberOfLines = 0;

// [cell setNeedsUpdateConstraints];

// [cell updateConstraintsIfNeeded];

//

// CGSize cell =[text boundingRectWithSize:CGSizeMake(305*ScreenWidth/375,ScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15*ScreenWidth/375]} context:nil].size;

// cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));

//算出label的行数和高度

CGSizesize =[textboundingRectWithSize:CGSizeMake(CELL_CONTENT_WIDTH- (CELL_CONTENT_MARGIN*2),99999.0f)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:FONT_SIZE]}context:nil].size;

// [cell setNeedsLayout];

// [cell layoutIfNeeded];

//

// CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

// height += 1;

// return height;

CGFloatheight =MAX(size.height,44.0f);

//

returnheight + (CELL_CONTENT_MARGIN*13);


}


- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{


staticNSString*customCellIndentifier =@"HistoryMessageCell";

HistoryMessageCell*cell = (HistoryMessageCell*)[tableViewdequeueReusableCellWithIdentifier:customCellIndentifier];

if(cell ==nil){

NSArray*nib = [[NSBundlemainBundle]loadNibNamed:@"HistoryMessageCell"owner:selfoptions:nil];

cell = [nibobjectAtIndex:0];

}

//设置点击没有变色

cell.selectionStyle=UITableViewCellSelectionStyleNone;

cell.haolb.text=[self.tableDataobjectAtIndex:indexPath.row];

cell.haolb.lineBreakMode=NSLineBreakByWordWrapping;

cell.haolb.numberOfLines=0;

[cellsetNeedsUpdateConstraints];

[cellupdateConstraintsIfNeeded];

returncell;

}


@end