
- (voID)vIEwDIDLoad{ Nsstring *Path = [[NSBundle mainBundle] bundlePath];Nsstring *DataPath = [Path stringByAppendingPathComponent:[Nsstring stringWithFormat:@"%@.pList",Languagefile]];NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithContentsOffile:DataPath];self.reloadArray = [tempDict objectForKey:@"Rows"];}-(NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw{return [self.reloadArray count];}-(NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section{return 1;}- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath {// Get data for the current row Nsstring *textData = [reloadArray objectAtIndex:indexPath.section]CGfloat dataTextHeight = [self getLabelHeightForIndex:textData]; if(dataTextHeight < 44) { dataTextHeight = 44; } return dataTextHeight;}-(CGfloat)getLabelHeightForIndex:(Nsstring *)string{CGSize maximumSize = CGSizeMake(280,10000);CGSize labelHeightSize = [string sizeWithFont:[UIFont FontWithname:@"Helvetica" size:14.0f] constrainedToSize:maximumSize lineBreakMode:NSlineBreakByWorDWrapPing];if(labelHeightSize.height < 44){ labelHeightSize.height = 44;}return labelHeightSize.height;}-(UItableVIEwCell*)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{static Nsstring *CellIDentifIEr = @"Cell";static const int textVIEwTag = 1,textLabelTag = 2;UIImageVIEw *img = [[UIImageVIEw alloc] initWithImage:[UIImage imagenamed:@"standard_back.png"]];img.frame = tableVIEw.frame;tableVIEw.backgroundVIEw = img;UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];if (!cell) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr]; // First vIEw UIVIEw *textVIEw = [[UIVIEw alloc] initWithFrame: CGRectMake(0.0,0.0,280.0,36.00)]; textVIEw.tag = textVIEwTag; textVIEw.autoresizingMask = UIVIEwautoresizingFlexibleWIDth; [cell.contentVIEw addSubvIEw:textVIEw]; // First label UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0,270.0,36.00)]; textLabel.tag = textLabelTag; textLabel.Font = [UIFont FontWithname:@"Helvetica-Bold" size:14.0f]; textLabel.textcolor = [UIcolor whitecolor]; textLabel.backgroundcolor = [UIcolor clearcolor]; textLabel.numberOflines = 0; textLabel.lineBreakMode = NSlineBreakByWorDWrapPing; textLabel.autoresizingMask = UIVIEwautoresizingFlexibleWIDth; // textLabel.clipsToBounds = YES; [cell.contentVIEw addSubvIEw:textLabel];} Nsstring *textData = [reloadArray objectAtIndex:(indexPath.section)]; CGfloat dataTextHeight = [self getLabelHeightForIndex:textData]; UIVIEw *textVIEw = [cell.contentVIEw vIEwWithTag:textVIEwTag]; CGRect textVIEwFrame = textVIEw.frame; textVIEw.frame = CGRectMake(0.0,textVIEwFrame.size.wIDth,dataTextHeight); UILabel *textLabel = [cell.contentVIEw vIEwWithTag:textLabelTag]; CGRect textLabelFrame = textLabel.frame; textLabel.frame = CGRectMake(10.0,textLabelFrame.size.wIDth,dataTextHeight); textLabel.text = textData; textLabel.backgroundcolor= [UIcolor clearcolor]; textLabel.textAlignment = NSTextAlignmentCenter;cell.backgroundcolor = [UIcolor colorWithWhite:0 Alpha:.65];cell.textLabel.numberOflines = 0; // Multilinecell.textLabel.lineBreakMode = NSlineBreakByWorDWrapPing;cell.textLabel.autoresizingMask = UIVIEwautoresizingFlexibleWIDth | UIVIEwautoresizingFlexibleHeight;return cell;} 提前致谢.
解决方法 这是我在我的应用程序中使用的代码的一部分.它对我很有用.如果你需要帮助,请打电话给我.- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath;{CGSize constraintSize = {230.0,20000}; //230 is cell wIDth & 20000 is max height for cellCGSize neededSize = [ [Nsstring stringWithFormat:@"%@",[cellar objectAtIndex:indexPath.row]] sizeWithFont:[UIFont FontWithname:@"HelveticaNeue-Medium" size:15.0f] constrainedToSize:constraintSize lineBreakMode:UIlineBreakModeCharacterWrap];return MAX(45,neededSize.height +33);}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{static Nsstring *CellIDentifIEr = @"Cell";UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];{ cell = [[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr] autorelease];}CGSize constraintSize = {230.0,20000};UILabel* label = [[UILabel alloc] init];[label setNumberOflines:0];label.backgroundcolor = [UIcolor clearcolor];[label setFont:[UIFont FontWithname:@"HelveticaNeue-Medium" size:15.0f]];label.adjustsFontSizetoFitWIDth = NO;CGSize neededSize = [ [Nsstring stringWithFormat:@"%@",[cellar objectAtIndex:indexPath.row] ] sizeWithFont:[UIFont FontWithname:@"HelveticaNeue-Medium" size:15.0f] constrainedToSize:constraintSize lineBreakMode:UIlineBreakModeCharacterWrap];// NSLog(@"Height%f",neededSize.height);//NSLog(@"wIDth%f",neededSize.wIDth);[label setText:[Nsstring stringWithFormat:@"%@",[cellar objectAtIndex:indexPath.row] ]];[label setFrame:CGRectMake(10,2,230,MAX(neededSize.height+30,44.0f))];[[cell contentVIEw] addSubvIEw:label];cell.selectionStyle=UItableVIEwCellSelectionStyleNone;return cell;} 希望能帮助到你.!!!
总结以上是内存溢出为你收集整理的ios – 动态改变目标C中单元格的高度全部内容,希望文章能够帮你解决ios – 动态改变目标C中单元格的高度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)