2

UITableViewオンラインの Web サービスで入力する基本的ながありますが、 textView.

セルを埋める方法は次のとおりです。

UITextView *textView = (UITextView *)[cell viewWithTag:106];
textView.text = [[stories objectAtIndex:indexPath.row] objectForKey:@"texte"];

私のcellForRow方法で:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

私はこれを試しましたが、エラーが発生しましたEXC_BAD_ACCESS

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PerleCell"];
    UITextView *textView = (UITextView *)[cell viewWithTag:106];
    textView.text = [[stories objectAtIndex:indexPath.row] objectForKey:@"texte"];
    CGFloat *heightCell =  (CGFloat*)textView.text.length;
    return *heightCell;
}
4

1 に答える 1

1

次のメソッドでは、textView に従ってセルの高さを変更できます。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Here check length of your textView
    // and after getting length return that length;
    NSString *myString = [[stories objectAtIndex:indexPath.row] objectForKey:@"texte"];
    CGSize maximumSize = CGSizeMake(300, 9999);
    UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:14];
    CGSize myStringSize = [myString sizeWithFont:myFont constrainedToSize:maximumSize lineBreakMode:UILineBreakModeWordWrap];
    return size.height;
}

cellForRowAtIndexPath メソッドでも同様に文字列の幅を計算し、それに応じて yourtextView の幅のフレームを指定します。その後、セルの contentView にテキストビューを追加します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     // Create cell here by using any style and for this you can google some what that how to create cell in UITableView
     // Here check length of your textView
     // and after getting length return that length;
     NSString *myString = [[stories objectAtIndex:indexPath.row] objectForKey:@"texte"];
     CGSize maximumSize = CGSizeMake(300, 9999);
     UIFont *myFont = [UIFont fontWithName:@"Helvetica" size:14];
     CGSize myStringSize = [myString sizeWithFont:myFont constrainedToSize:maximumSize lineBreakMode:UILineBreakModeWordWrap];
     UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0,0,300,size.height)];
     textView.text = myString;
     [cell.contentView addSubView:textView];
     return cell;
}
于 2013-02-17T14:42:56.127 に答える