我的UITableview
正在显示数据,但是一个部分中的文字正在移出框中并显示在其他部分中..我不知道为什么?
这是我的代码:
if(indexPath.section == 0){
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.numberOfLines=3;
cell.detailTextLabel.textColor=[UIColor colorWithRed:0.40 green:0.40 blue:0.40 alpha:1.0];
cell.textLabel.text=[NSString stringWithFormat:@"School Hours:"];
cell.detailTextLabel.text=[NSString stringWithFormat:@"Take in time: %@ \nDissmiss time:%@ \nPhone No: %@ ",[array objectAtIndex:indexPath.row],[array1 objectAtIndex:indexPath.row],[array2 objectAtIndex:indexPath.row]];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];
}
else if(indexPath.section == 1){cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.textLabel.textColor = [UIColor blackColor];
cell.detailTextLabel.numberOfLines=3;
cell.detailTextLabel.textColor=[UIColor colorWithRed:0.40 green:0.40 blue:0.40 alpha:1.0];
cell.textLabel.text=[NSString stringWithFormat:@"Principal"];
NSString *thumbs = [NSString stringWithFormat:@"%@", [imagearray objectAtIndex:indexPath.row]];
UIImage *thumbs1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:thumbs]]];
// cell.imageView.image = [UIImage imageNamed:th];
cell.detailTextLabel.text=[NSString stringWithFormat:@" %@ ",[imagearray objectAtIndex:indexPath.row]] ;
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.detailTextLabel.backgroundColor=[UIColor clearColor];}
任何人都可以让我知道出了什么问题。我甚至为这些部分设置了页眉和页脚。
答案 0 :(得分:0)
设置单元格的高度例如......
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *titleString = yourTitleString;///here just write your string here
NSString *detailString = [NSString stringWithFormat:@"Take in time: %@ \nDissmiss time:%@ \nPhone No: %@ ",[array objectAtIndex:indexPath.row],[array1 objectAtIndex:indexPath.row],[array2 objectAtIndex:indexPath.row]];
CGSize titleSize = [titleString sizeWithFont:[UIFont boldSystemFontOfSize:18] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
CGSize detailSize = [detailString sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
return detailSize.height+titleSize.height;
}
我只是为单元格的动态高度设置公共单元格的代码,请参阅cellForRowAtIndexPath
方法的下方代码...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"YourTitle";
cell.textLabel.font = [UIFont boldSystemFontOfSize:18];
cell.textLabel.numberOfLines = ceilf([@"YourTitle" sizeWithFont:[UIFont boldSystemFontOfSize:18] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20.0);
cell.detailTextLabel.text = [NSString stringWithFormat:@"Take in time: %@ \nDissmiss time:%@ \nPhone No: %@ ",[array objectAtIndex:indexPath.row],[array1 objectAtIndex:indexPath.row],[array2 objectAtIndex:indexPath.row]];
cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
cell.detailTextLabel.numberOfLines = ceilf([[NSString stringWithFormat:@"Take in time: %@ \nDissmiss time:%@ \nPhone No: %@ ",[array objectAtIndex:indexPath.row],[array1 objectAtIndex:indexPath.row],[array2 objectAtIndex:indexPath.row]]; sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap].height/20.0);
return cell;
}
答案 1 :(得分:0)
对于如此庞大的数据,您需要截断数据以显示它。 为此,您可以使用:
[[cell detailTextLabel] setLineBreakMode:UILineBreakModeTailTruncation];
cell.detailTextLabel.numberOfLines = 0;
另一个选择是您需要使用heightForRowAtIndexPath
委托来调整tableViewCell的高度。