Objective c 分组UITableView中的UITextView';s细胞
请解释一下:如何以编程方式在UITableViewCell中创建UITextView(UITableView具有分组样式)。文本视图的大小应等于单元格的大小 UITextView的文本和边框(左上角)之间有一个间隙,因此我需要正确的坐标来正确地将文本视图放置在单元格上 更新:我已经解决了我的问题。见下面我的自我回答。谢谢 给你:Objective c 分组UITableView中的UITextView';s细胞,objective-c,ios,uitableview,uitextview,Objective C,Ios,Uitableview,Uitextview,请解释一下:如何以编程方式在UITableViewCell中创建UITextView(UITableView具有分组样式)。文本视图的大小应等于单元格的大小 UITextView的文本和边框(左上角)之间有一个间隙,因此我需要正确的坐标来正确地将文本视图放置在单元格上 更新:我已经解决了我的问题。见下面我的自我回答。谢谢 给你: - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIn
- (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;
}
给你:
- (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;
}
设置UITextView的“contentInset”
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *sCellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDetail
reuseIdentifier:sCellIdentifier];
}
UITextView *textView = [UITextView alloc]init];
textView.contentInset = UIEdgeInsetsMake(-8,-8,-8,-8); //Change according ur requirement
textView.frame = cell.frame;
[textView setUserInteractionEnabled:FALSE];
[textView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubView:textView];
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*sCellIdentifier=@“单元格”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
如果(!单元格)
{
单元格=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDetail
重用标识符: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];
返回单元;
}
设置UITextView的“contentInset”
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *sCellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDetail
reuseIdentifier:sCellIdentifier];
}
UITextView *textView = [UITextView alloc]init];
textView.contentInset = UIEdgeInsetsMake(-8,-8,-8,-8); //Change according ur requirement
textView.frame = cell.frame;
[textView setUserInteractionEnabled:FALSE];
[textView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubView:textView];
return cell;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*sCellIdentifier=@“单元格”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:sCellIdentifier];
如果(!单元格)
{
单元格=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDetail
重用标识符: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];
返回单元;
}
很简单:
textView.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
很简单:
textView.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
您最好的选择可能是在问题中显示您当前的代码,以便人们提出改进建议。创建
UITextView
对象的实例,并将其作为子视图添加到UITableCellView
中,并确保在重用任何旧的UITableCell
时,如果不想不必要地浪费内存,请不要将UITextView
的新实例再次添加到同一单元格中。为了更清晰,我对问题进行了编辑。要将问题标记为已解决,请接受答案,不要更新问题的标题。最好的办法可能是在问题中显示当前代码,以便人们提出改进建议。创建UITextView
对象的实例,并将其作为子视图添加到UITableCellView
中,并确保在重用任何旧的UITableCell
时,如果不想不必要地浪费内存,请不要将UITextView
的新实例再次添加到同一单元格中。我已编辑了该问题以提高清晰度。若要将问题标记为已解决,请接受答案,不要更新问题的标题。我要创建的是UITextView对象,而不是UITextField。UITextView的文本与其边框(左上角)之间存在间隙,因此我需要正确的坐标将文本视图正确放置在单元格上。我要创建的是UITextView对象,而不是UITextField。UITextView的文本和边框(左上角)之间有一个间隙,因此我需要正确的坐标来正确地将文本视图放置在单元格上。