1

説明してください: UITableViewCell で UITextView をプログラムで作成する方法 (UITableView にはグループ化されたスタイルがあります)。テキスト ビューのサイズは、セルのサイズと同じにする必要があります。

UITextView にはテキストと境界線 (左上隅) の間に隙間があるため、テキスト ビューをセルに適切に配置するには正しい座標が必要です。

更新:質問を解決しました。以下の私の自己回答を参照してください。ありがとう!

4

3 に答える 3

1

それは簡単でした:

    textView.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
于 2012-07-25T06:14:36.483 に答える
0

UITextViewの「contentInset」を設定

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

    static NSString *sCellIdentifier = @"セル";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];

    もし (!セル)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDetail
                                      reuseIdentifier:sCellIdentifier];
    }
    UITextView *textView = [UITextView alloc]init];
    textView.contentInset = UIEdgeInsetsMake(-8,-8,-8,-8); //要件に応じて変更
    textView.frame = cell.frame;
    [textView setUserInteractionEnabled:FALSE];
    [textView setBackgroundColor:[UIColor clearColor]];
    [cell.contentView addSubView:textView];
    セルを返します。
}
于 2012-07-24T16:50:25.613 に答える
0

どうぞ:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Prototype Cell"];
    UITextField *textfield;
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                      reuseIdentifier:@"Prototype Cell"];
        textfield = [[UITextField alloc] init];
        [cell.contentView addSubview:textfield];
        textfield.tag = TEXT_FIELD_TAG; //Suppose you defined TEXT_FIELD_TAG someplace else
    }
    else 
    {
        textfield = [self.view viewWithTag: TEXT_FIELD_TAG];
        textfield.frame = cell.frame;
    }
    return cell;
}
于 2012-07-24T15:57:21.297 に答える