ios - Increase table row height dynamically -
i have table 1 custom cell 1 label , 1 textfield.am re-using same cell 5 rows. want display 1 view beneath textfield if user enters on textfield. when entering data in first textfield view should hidden other rows , respectively other rows. default height must 120 , when displaying view row height should increased 250. here code,
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { return 120; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"detailstablecell"; cell = (newsdetailstableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[newsdetailstableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; } if (indexpath.row == 0) { cell.newview.tag = 200; } else if (indexpath.row == 1) { cell.newview.tag = 201; } else { cell.newview.tag = 202; } return cell; } here new view uiview displaying on text change.
- (ibaction)textfieldchanged:(uitextfield *)textfield replacementstring:(nsstring *)string { nsindexpath *indexpath = [newstable indexpathforcell:(newsdetailstableviewcell*)[[textfield superview] superview]]; nsindexpath *mypath = [nsindexpath indexpathforrow:indexpath.row insection:indexpath.section]; newsdetailstableviewcell *newstablecell = (newsdetailstableviewcell*)[newstable cellforrowatindexpath:mypath]; if (indexpath.row == 0 && newstablecell.newview.tag == 100) { newstable.rowheight = 250; newstablecell.newview.hidden = false; } else if (indexpath.row == 1 && newstablecell.newview.tag.tag == 101) { newstable.rowheight = 250; newstablecell.newview.hidden = false; } else { newstable.rowheight = 250; newstablecell.newview.hidden = false; } } am getting view in text change row height not getting changed. still showing 120 height.
also tried this,
nsarray* rowstobereloaded = [nsarray arraywithobjects:indexpath, nil]; [newstable reloadrowsatindexpaths:rowstobereloaded withrowanimation:uitableviewrowanimationnone]; but didn't work. should re-load tableview again in text change? or missing something?
you have modify logic in below method:
the selectedrownum can modified per row in textfield shown. also, cellforrowatindexpath not used setting height of rows in tableview. everytime, call reloaddata or reloadindexes heightforrowatindexpath method called.
Comments
Post a Comment