0

StackOverflow の少年は、ラベルの内容に基づいてセルの高さを自動的に設定するのに役立ちました...

彼の方法を実装しましたが、tavleview をスクロールすると、各セル内のすべてのテキストが重なって何も読み取れません...このコードの何が問題なのか教えていただけますか?

ここに画像の説明を入力

いくつかのコードに取り組んでいるため、CGSize を変更する必要がありました。たとえば、ios7 は廃止されました。

 

 CGSize size = [comment sizeWithFont: [UIFont systemFontOfSize: 14] constrainedToSize: lineBreakMode constraint: UILineBreakModeWordWrap];

助けてください。

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

    PFObject *object = [self objectAtIndexPath:indexPath];
    //Here you are getting the comment again.  This is necessary to determine how tall you need
    //the cell to be
    NSString *comment = [object objectForKey:(@"Testo")];

    // Again you are getting the constraints because you are going to us this size
    // to constrain the height of the cell just like you determined the size for the label.
    CGSize constraint = CGSizeMake(250 - (10 * 2), 10000.0f);

    // Again, determining the size that we will need for the label, because it will drive
    // the height of the cell
    UIFont *FONT = [UIFont systemFontOfSize:11];

     CGSize size = [comment boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT }context:nil].size;

    //  Finally, we can determine the height for the cell!
    CGFloat height = MAX(size.height, 44.0f);

    //  return the height, which is the height of the label plus some extra space to make
    //  it look good.
    return height + (10 * 2);
}

// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    NSString *text = [object objectForKey:@"Testo"];


    CGSize constraint = CGSizeMake(250 - (10 * 2), 10000.0f);

    // This is determining the size that you will need for the label based on the comment
    // length and the contraint size

    UIFont *FONT = [UIFont systemFontOfSize:11];

    CGSize size = [text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FONT }context:nil].size;

    //  Here you are creating your label and initializing it with the frame that you have
    //  determined by your size calculations above
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, MAX(size.height, 44.0f) + 20.0f)];

    // setting up the label properties


    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.text = text;
    label.font = [UIFont systemFontOfSize:11];

    // adding the label view to the cell that you have created
    [cell.contentView addSubview:label];

    // Configure the cell


    return cell;
}
4

1 に答える 1