説明してください: UITableViewCell で UITextView をプログラムで作成する方法 (UITableView にはグループ化されたスタイルがあります)。テキスト ビューのサイズは、セルのサイズと同じにする必要があります。
UITextView にはテキストと境界線 (左上隅) の間に隙間があるため、テキスト ビューをセルに適切に配置するには正しい座標が必要です。
更新:質問を解決しました。以下の私の自己回答を参照してください。ありがとう!
説明してください: UITableViewCell で UITextView をプログラムで作成する方法 (UITableView にはグループ化されたスタイルがあります)。テキスト ビューのサイズは、セルのサイズと同じにする必要があります。
UITextView にはテキストと境界線 (左上隅) の間に隙間があるため、テキスト ビューをセルに適切に配置するには正しい座標が必要です。
更新:質問を解決しました。以下の私の自己回答を参照してください。ありがとう!
それは簡単でした:
textView.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
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];
セルを返します。
}
どうぞ:
- (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;
}