Date(12.1.2012) Time(12.00pm)Cost: .00Details
我在 – (CGfloat)tableVIEw中指定了行高100:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath;.但是,现在细节有时会从服务器返回空(Null).在那个时候我需要从单元格中删除Details标签并将特定的单元格(行)高度更改为70.我该怎么做?我在谷歌搜索了我的水平.但是,我仍然很困惑这样做.你能帮我么?谢谢.我从这个链接中得到了一些想法 – http://www.cimgf.com/2009/09/23/uitablevIEwcell-dynamic-height/.他们只使用一个标签来调整行高.请帮我.
- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 90;} - (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *CellIDentifIEr = @"Cell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if (cell == nil) { cell = [[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr] autorelease]; UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,100,30)]; dateLabel.tag = 100; dateLabel.backgroundcolor = [UIcolor clearcolor]; dateLabel.Font = [UIFont FontWithname:@"Helvetica" size:16]; dateLabel.Font = [UIFont boldSystemFontOfSize:16]; dateLabel.highlightedTextcolor = [UIcolor whitecolor]; [cell.contentVIEw addSubvIEw: dateLabel]; UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120,200,25)]; timeLabel.tag = 101; timeLabel.backgroundcolor = [UIcolor clearcolor]; timeLabel.Font = [UIFont FontWithname:@"Helvetica" size:14]; timeLabel.highlightedTextcolor = [UIcolor whitecolor]; [cell.contentVIEw addSubvIEw: timeLabel]; UILabel *costLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,30,300,25)]; costLabel.tag = 102; costLabel.backgroundcolor = [UIcolor clearcolor]; costLabel.Font = [UIFont FontWithname:@"Helvetica" size:14]; costLabel.Font = [UIFont boldSystemFontOfSize:14]; costLabel.highlightedTextcolor = [UIcolor whitecolor]; [cell.contentVIEw addSubvIEw: costLabel]; UILabel *eventLabel = [[UILabel alloc] initWithFrame:CGRectMake(10,60,25)]; eventLabel.tag = 103; eventLabel.backgroundcolor = [UIcolor clearcolor]; eventLabel.Font = [UIFont FontWithname:@"Helvetica" size:14]; eventLabel.Font = [UIFont boldSystemFontOfSize:14]; eventLabel.highlightedTextcolor = [UIcolor whitecolor]; [cell.contentVIEw addSubvIEw: eventLabel]; } UILabel *dateLabel = (UILabel *) [cell.contentVIEw vIEwWithTag:100]; dateLabel.text = [DateArray objectAtIndex:indexPath.row]; UILabel * timeLabel = (UILabel *) [cell.contentVIEw vIEwWithTag:101]; timeLabel.text = [timeArray objectAtIndex:indexPath.row]; UILabel * costLabel = (UILabel *) [cell.contentVIEw vIEwWithTag:102]; costLabel.text = [costArray objectAtIndex:indexPath.row]; UILabel *eventLabel = (UILabel *) [cell.contentVIEw vIEwWithTag:103]; Nsstring *description = [eventArray objectAtIndex:indexPath.row]; if([description isEqualToString:@""]) { eventLabel.text = @""; // Here i don't want to show this label and resize(reduce) the row height to 60; } else { eventLabel.text = description; } return cell; }
我怎样才能做到这一点?谢谢.
解决方法 返回高度时,请检查详细说明是否为空.如果是60.- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath{ Nsstring *description = [eventArray objectAtIndex:indexPath.row];if([description isEqualToString:@""]) return 60else{ return 90;}}
此外,您需要在cellForRowAtIndexPath:中的同一if语句中使用@“Details”删除标签.事先标记它,从子视图中识别它并从单元格中删除它.
总结以上是内存溢出为你收集整理的ios – 在iPhone中动态更改UITableviewCell高度?全部内容,希望文章能够帮你解决ios – 在iPhone中动态更改UITableviewCell高度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)