ios 8 uitableviewcell身高问题

时间:2015-09-16 16:01:09

标签: objective-c uitableview ios7 ios8

我在iOS 8上调整uitablecell高度时遇到一些问题。

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){

    // Calculate a height based on a cell
    if(!self.customCell) {
        self.customCell = [self.availableTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    }
    NSLog(@"initial height: %f", self.customCell.contentView.frame.size.height);


    //retrieve current object for use with this indexpath.row
    AvailableRouteObject *availableRouteObj = [[AvailableRouteObject alloc] init];

    availableRouteObj = [availableRoutesArray objectAtIndex:indexPath.row];

    dateFormatter = [[NSDateFormatter alloc] init]; // here we create NSDateFormatter object for change the Format of date..
    [dateFormatter setDateFormat:@"yyyy-MM-dd"]; //// here set format of date which is in your output date (means above str with format)

    NSDate *date = [dateFormatter dateFromString: availableRouteObj.Date]; // here you can fetch date from string with define format

    dateFormatter2 = [[NSDateFormatter alloc] init];
    [dateFormatter2 setDateFormat:@"MMM dd"];// here set format which you want...

    NSString *convertedDate = [dateFormatter2 stringFromDate:date]; //here convert date in NSString

    NSString *dateAppend = [NSString stringWithFormat:@"%@\n%@", convertedDate, availableRouteObj.Day];


    self.customCell.date.text = dateAppend;
    self.customCell.areaDetails.text = availableRouteObj.Area;
    self.customCell.collectionDetails.text = availableRouteObj.BakeryDisplay;
    self.customCell.deliveryDetails.text = availableRouteObj.HomeDisplay;

    //layout the cell
    //[self.customCell setNeedsUpdateConstraints];
    [self.customCell setNeedsLayout];
    //[self.customCell updateConstraintsIfNeeded];
    [self.customCell layoutIfNeeded];

    //get the hieght for the cell
    CGFloat height = [self.customCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

    NSLog(@"height: %f", height);

    //return height + 1.0f;
    return height + 1.0f;

}else{

    NSLog(@"YES! I AM iOS 8");
    availableTableView.estimatedRowHeight = 340;

    return UITableViewAutomaticDimension;

}

}

可以在此处查看应用屏幕截图和故事板(使用检查员)以便更好地理解:https://drive.google.com/folderview?id=0B9RtiTVVjrzVRlpQWmdZTjJPZE0&usp=sharing

请告诉我如何解决问题,以便iOS 8中的uitablecell与iOS 7中的uitablecell相同。

感谢。我已经尝试解决这个问题好几天但我无法这样做。

0 个答案:

没有答案