ios Tableviewcell添加TextView自適應(yīng)高度

Tableviewcell.h文件

#import "WXXCHZS_EditOutRegimentInfo_Text_Cell.h"

#import@interface WXXCHZS_EditOutRegimentInfo_Text_Cell : UITableViewCell

@property (nonatomic,strong)UILabel *nameLa;

@property (nonatomic,strong)TXL_placeholderTextView *contentLa;

@end

Tableviewcell.m文件

#import "WXXCHZS_EditOutRegimentInfo_Text_Cell.h"

@implementation WXXCHZS_EditOutRegimentInfo_Text_Cell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

? ? if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

? ? ? ? [self setupMain];

? ? }

? ? return self;

}

-(void)setupMain

{




? ? self.nameLa=[[UILabel alloc]init];

? ? [self.nameLa setTextAlignment:NSTextAlignmentLeft];

? ? [self.nameLa setFont:Font13];

? ? [self.nameLa setTextColor:[UIColor blackColor]];

? ? [self.contentView addSubview:self.nameLa];

? ? [self.nameLa mas_makeConstraints:^(MASConstraintMaker *make){

? ? ? ? make.left.mas_equalTo(16);

? ? ? ? make.top.mas_equalTo(15);

? ? ? ? make.right.mas_equalTo(-15);

? ? ? ? make.height.mas_equalTo(13);

? ? }];


? ? self.contentLa=[[TXL_placeholderTextView alloc]init];

? ? [self.contentLa setTextAlignment:NSTextAlignmentLeft];

? ? [self.contentLa setFont:Font14];

? ? [self.contentLa setTextColor:[UIColor blackColor]];

? ? [self.contentView addSubview:self.contentLa];

? ? [self.contentLa mas_makeConstraints:^(MASConstraintMaker *make){

? ? ? ? make.left.mas_equalTo(16);

? ? ? ? make.top.mas_equalTo(43);

? ? ? ? make.right.mas_equalTo(-15);

? ? ? ? make.bottom.mas_equalTo(-10);

? ? }];

}

控制器ViewController

#pragma mark -初始化

-(UITableView *)tableView

{

? ? if (!_tableView) {

? ? ? ? _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, KMainWidth, KMainHeight-kNavbarHeight) style:UITableViewStyleGrouped];

? ? ? ? _tableView.backgroundColor=LineColor;

? ? ? ? _tableView.delegate=self;

? ? ? ? _tableView.dataSource=self;

? ? ? ? _tableView.estimatedRowHeight=100;

? ? ? ? _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

? ? ? ? [_tableView registerClass:[WXXCHZS_EditOutRegimentInfo_Status_Cell class] forCellReuseIdentifier:@"WXXCHZS_EditOutRegimentInfo_Status_Cell"];

? ? ? ? [_tableView registerClass:[WXXCHZS_EditOutRegimentInfo_Text_Cell class] forCellReuseIdentifier:@"WXXCHZS_EditOutRegimentInfo_Text_Cell"];


? ? ? ? self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{

? ? ? ? ? ? [self headerRefresh];

? ? ? ? }];

? ? }

? ? return _tableView;


}

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

{

? ? if (indexPath.section==0) {


? ? ? ? WXXCHZS_EditOutRegimentInfo_Status_Cell *cell=[tableView dequeueReusableCellWithIdentifier:@"WXXCHZS_EditOutRegimentInfo_Status_Cell"];

? ? ? ? if (self.dataDict.allKeys.count) {

? ? ? ? ? ? cell.selectionStyle=UITableViewCellSelectionStyleNone;

? ? ? ? ? ? [cell.headerImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.dataDict[@"authorFace"]]] placeholderImage:[UIImage imageNamed:@"bg_richeng-1"]];

? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"%@",_dataDict[@"authorName"]]];

? ? ? ? ? ? [cell.phoneLa setText:[NSString stringWithFormat:@"%@",_dataDict[@"xchSn"]]];

? ? ? ? ? ? NSString * status;

? ? ? ? ? ? NSString *statusNss=_dataDict[@"tripStatus"];


? ? ? ? ? ? switch (statusNss.intValue) {

? ? ? ? ? ? ? ? case 0:

? ? ? ? ? ? ? ? ? ? status = @"未提交";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 1:

? ? ? ? ? ? ? ? ? ? status = @"待確認(rèn)";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 2:

? ? ? ? ? ? ? ? ? ? status = @"待支付(訂金)";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 3:

? ? ? ? ? ? ? ? ? ? status = @"待支付(全款)";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 4:

? ? ? ? ? ? ? ? ? ? status = @"已付款";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 5:

? ? ? ? ? ? ? ? ? ? status = @"待出發(fā)";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 6:

? ? ? ? ? ? ? ? ? ? status = @"進(jìn)行中";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 7:

? ? ? ? ? ? ? ? ? ? status = @"已完成";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 8:

? ? ? ? ? ? ? ? ? ? status = @"已評(píng)價(jià)";

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case 9:

? ? ? ? ? ? ? ? ? ? status = @"已關(guān)閉";

? ? ? ? ? ? ? ? ? ? break;


? ? ? ? ? ? ? ? default:

? ? ? ? ? ? ? ? ? ? status = @"";

? ? ? ? ? ? ? ? ? ? break;


? ? ? ? ? ? }

? ? ? ? ? ? [cell.stateLa setText:[NSString stringWithFormat:@"%@",status]];

? ? ? ? }

? ? ? ? return cell;

? ? }else{

? ? ? ? WXXCHZS_EditOutRegimentInfo_Text_Cell *cell=[tableView dequeueReusableCellWithIdentifier:@"WXXCHZS_EditOutRegimentInfo_Text_Cell"];

? ? ? ? cell.selectionStyle=UITableViewCellSelectionStyleNone;

? ? ? ? NSInteger row = [indexPath row];

? ? ? ? cell.contentLa.tag=row+100;

? ? ? ? cell.contentLa.scrollEnabled? =NO;

? ? ? ? cell.contentLa.textContainer.lineFragmentPadding = 0;

? ? ? ? cell.contentLa.textContainerInset = UIEdgeInsetsZero;

? ? ? ? cell.contentLa.autocorrectionType = UITextAutocorrectionTypeNo;

? ? ? ? cell.contentLa.autocapitalizationType = UITextAutocapitalizationTypeNone;

? ? ? ? cell.contentLa.returnKeyType = UIReturnKeyDefault;

? ? ? ? if (self.dataDict.allKeys.count) {

? ? ? ? ? ? if ([self.isMessage integerValue]==0) {

? ? ? ? ? ? ? ? cell.contentLa.editable=NO;

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? cell.contentLa.delegate=self;

? ? ? ? ? ? ? ? cell.contentLa.editable=YES;

? ? ? ? ? ? ? ? if (indexPath.row==0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚懶谐堂Q"];

? ? ? ? ? ? ? ? }else if (indexPath.row==1){

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚懶谐毯桨嘈畔?];

? ? ? ? ? ? ? ? }else if (indexPath.row==2){

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚懠系攸c(diǎn)"];

? ? ? ? ? ? ? ? }else if (indexPath.row==3){

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚憣?dǎo)游真實(shí)姓名"];

? ? ? ? ? ? ? ? }else if (indexPath.row==4){

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚懢o急電話"];

? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? [cell.contentLa setPlaceholder:@"請(qǐng)?zhí)顚懷a(bǔ)充說明"];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? if (indexPath.row==0){

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"行程名稱"]];

? ? ? ? ? ? ? ? if ([self.dict[@"title"] length]>0) {

? ? ? ? ? ? ? ? ? ? cell.contentLa.editable=NO;

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"title"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }else if (indexPath.row==1){

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"往返航班"]];

? ? ? ? ? ? ? ? if ([self.dict[@"transportInfo"] length]>0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"transportInfo"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }else if (indexPath.row==2){

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"集合安排"]];

? ? ? ? ? ? ? ? if ([self.dict[@"jiheInfo"] length]>0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"jiheInfo"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }else if (indexPath.row==3){

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"導(dǎo)游領(lǐng)隊(duì)"]];

? ? ? ? ? ? ? ? if ([self.dict[@"talentInfo"] length]>0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"talentInfo"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }else if (indexPath.row==4){

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"緊急電話"]];

? ? ? ? ? ? ? ? if ([self.dict[@"jinjiPhone"] length]>0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"jinjiPhone"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? [cell.nameLa setText:[NSString stringWithFormat:@"補(bǔ)充說明"]];

? ? ? ? ? ? ? ? if ([self.dict[@"remark"] length]>0) {

? ? ? ? ? ? ? ? ? ? [cell.contentLa setText:[NSString stringWithFormat:@"%@",self.dict[@"remark"]]];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return cell;

? ? }

}

- (void)textViewDidChange:(UITextView *)textView

{

? ? if (textView.tag==100) {

? ? ? ? self.dict[@"title"] = textView.text;

? ? }else if (textView.tag==101){

? ? ? ? self.dict[@"transportInfo"] = textView.text;

? ? }else if (textView.tag==102){;

? ? ? ? self.dict[@"jiheInfo"] = textView.text;

? ? }else if (textView.tag==103){

? ? ? ? self.dict[@"talentInfo"] = textView.text;

? ? }else if (textView.tag==104){

? ? ? ? self.dict[@"jinjiPhone"] = textView.text;

? ? }else if (textView.tag==105){

? ? ? ? self.dict[@"remark"] = textView.text;

? ? }

? ? CGRect bounds = textView.bounds;

? ? //? ? 計(jì)算 text view 的高度

? ? CGSize maxSize = CGSizeMake(KMainWidth-30, CGFLOAT_MAX);

? ? CGSize newSize = [textView sizeThatFits:maxSize];

? ? bounds.size=newSize;

? ? textView.bounds = bounds;

? ? // 讓 table view 重新計(jì)算高度

? ? UITableView *tableView = [self tableView];

? ? [tableView beginUpdates];

? ? [tableView endUpdates];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

? ? return 2;

}

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

{

? ? if (section==0) {

? ? ? ? return 1;

? ? }else{

? ? ? ? return 6;

? ? }

}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

? ? if (section==0) {

? ? ? ? return 0.1;

? ? }else{

? ? ? ? return 10;

? ? }

}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

? ? if (section==0) {

? ? ? ? return nil;

? ? }else{

? ? ? ? UIView *headerView;

? ? ? ? if (!headerView) {

? ? ? ? ? ? headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KMainWidth, 10)];

? ? ? ? ? ? headerView.backgroundColor=LineColor;

? ? ? ? }

? ? ? ? return headerView;

? ? }

}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

? ? if (section==1) {

? ? ? ? return 81;

? ? }else{

? ? ? ? return 0.1;

? ? }

}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

? ? if (section==0) {

? ? ? ? return nil;

? ? }else{

? ? ? ? UIView *footerView;

? ? ? ? if (!footerView) {


? ? ? ? ? ? footerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KMainWidth, 81)];

? ? ? ? ? ? footerView.backgroundColor=LineColor;


? ? ? ? ? ? UIButton *saveBtn=[[UIButton alloc]initWithFrame:CGRectMake(15, 30, KMainWidth-30, 44)];

? ? ? ? ? ? [saveBtn setTitle:@"保存" forState:UIControlStateNormal];

? ? ? ? ? ? saveBtn.titleLabel.font=Font18;

? ? ? ? ? ? [saveBtn addTarget:self action:@selector(DoSaveClick) forControlEvents:UIControlEventTouchUpInside];

? ? ? ? ? ? [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

? ? ? ? ? ? saveBtn.backgroundColor=GreenMainColor;

? ? ? ? ? ? [footerView addSubview:saveBtn];

? ? ? ? }

? ? ? ? return footerView;

? ? }

}

- (void)setExtraCellLineHidden: (UITableView *)tableView

{

? ? UIView *view =[ [UIView alloc]init];

? ? view.backgroundColor = [UIColor clearColor];

? ? [tableView setTableFooterView:view];

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末肥荔,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子僵井,更是在濱河造成了極大的恐慌府喳,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,755評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件滋将,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)徊哑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,305評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來聪富,“玉大人莺丑,你說我怎么就攤上這事《章” “怎么了梢莽?”我有些...
    開封第一講書人閱讀 165,138評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)奸披。 經(jīng)常有香客問我昏名,道長(zhǎng),這世上最難降的妖魔是什么阵面? 我笑而不...
    開封第一講書人閱讀 58,791評(píng)論 1 295
  • 正文 為了忘掉前任轻局,我火速辦了婚禮,結(jié)果婚禮上样刷,老公的妹妹穿的比我還像新娘仑扑。我一直安慰自己,他們只是感情好颂斜,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,794評(píng)論 6 392
  • 文/花漫 我一把揭開白布夫壁。 她就那樣靜靜地躺著,像睡著了一般沃疮。 火紅的嫁衣襯著肌膚如雪盒让。 梳的紋絲不亂的頭發(fā)上梅肤,一...
    開封第一講書人閱讀 51,631評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音邑茄,去河邊找鬼姨蝴。 笑死,一個(gè)胖子當(dāng)著我的面吹牛肺缕,可吹牛的內(nèi)容都是我干的左医。 我是一名探鬼主播,決...
    沈念sama閱讀 40,362評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼同木,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼浮梢!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起彤路,我...
    開封第一講書人閱讀 39,264評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤秕硝,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后洲尊,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體远豺,經(jīng)...
    沈念sama閱讀 45,724評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年坞嘀,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了躯护。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,040評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡丽涩,死狀恐怖棺滞,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情内狸,我是刑警寧澤检眯,帶...
    沈念sama閱讀 35,742評(píng)論 5 346
  • 正文 年R本政府宣布,位于F島的核電站昆淡,受9級(jí)特大地震影響锰瘸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜昂灵,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,364評(píng)論 3 330
  • 文/蒙蒙 一避凝、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧眨补,春花似錦管削、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,944評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春含潘,著一層夾襖步出監(jiān)牢的瞬間饲做,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,060評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工遏弱, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留盆均,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,247評(píng)論 3 371
  • 正文 我出身青樓漱逸,卻偏偏與公主長(zhǎng)得像泪姨,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子饰抒,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,979評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 概述在iOS開發(fā)中UITableView可以說是使用最廣泛的控件肮砾,我們平時(shí)使用的軟件中到處都可以看到它的影子,類似...
    liudhkk閱讀 9,047評(píng)論 3 38
  • 1.badgeVaule氣泡提示 2.git終端命令方法> pwd查看全部 >cd>ls >之后桌面找到文件夾內(nèi)容...
    i得深刻方得S閱讀 4,667評(píng)論 1 9
  • 1袋坑、禁止手機(jī)睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa閱讀 1,117評(píng)論 1 6
  • 20171220打卡 目標(biāo):健康唇敞、夫妻和諧、自我成長(zhǎng) 好種子: 1.經(jīng)絡(luò)操15分咒彤,健康的種子(...
    南哲玲閱讀 106評(píng)論 0 0
  • 洛陽才子他鄉(xiāng)逢,身家渴求萬谷鐘咒精。 豐彩幾欲迷人眼镶柱,背后辛酸應(yīng)相同。
    陽春閱讀 182評(píng)論 0 5