gpt4 book ai didi

ios - UITableCellView.contentView 中的标签在使用自动调整大小时显示两次

转载 作者:行者123 更新时间:2023-11-28 23:09:55 25 4
gpt4 key购买 nike

我正在使用 Grouped UITableView 并添加 UITableViewCells 两个 UILabel,并将它们添加到单元格的 contentView。我还在我的应用程序中在此 UITableView 上实现编辑模式。

我用lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth; 以减小文本的宽度,以便在编辑模式下显示的删除红色按钮不会覆盖我的文本。

现在我看到的是,当我在不处于编辑模式下滚动表格时,标签显示两次,就好像它同时处于编辑模式和退出编辑模式一样。

这是代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}


CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);

lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];

lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;

lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;

[lblDetail setFont:[UIFont fontWithName:@"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:@"Arial-BoldMT" size:15]];

lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;

lblTitle.text = @"054-9700583";
lblDetail.text = @"שאלה:במה אפשר לעזור לך?";

[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];

cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:@"girl.png"];

[lblDetail release];
[lblTitle release];

return cell;
}

最佳答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];


CGRect DetailLabelFrame = CGRectMake(52, 25, 200, 35);
CGRect TitleLabelFrame = CGRectMake(52, 5, 200, 25);

lblDetail = [[UILabel alloc]init];
lblTitle = [[UILabel alloc]init];

lblDetail.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
lblTitle.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;

lblDetail.frame = DetailLabelFrame;
lblDetail.lineBreakMode = UILineBreakModeWordWrap;
lblDetail.backgroundColor = [UIColor clearColor];
lblDetail.numberOfLines = 2;

lblTitle.frame = TitleLabelFrame;
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.frame = TitleLabelFrame;

[lblDetail setFont:[UIFont fontWithName:@"Arial" size:14]];
[lblTitle setFont:[UIFont fontWithName:@"Arial-BoldMT" size:15]];

lblDetail.textAlignment = UITextAlignmentRight;
lblTitle.textAlignment = UITextAlignmentRight;
[cell.contentView addSubview:lblDetail];
[cell.contentView addSubview:lblTitle];

lblDetail.tag = 10;
lblTitle.tag = 11;

}


lblDetail = (UILabel*)[cell.contentView viewWithTag:10];

lblTitle = (UILabel*)[cell.contentView viewWithTag:11];

lblTitle.text = @"054-9700583";
lblDetail.text = @"שאלה:במה אפשר לעזור לך?";

cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
cell.imageView.image = [UIImage imageNamed:@"girl.png"];

[lblDetail release];
[lblTitle release];

return cell;
}

你的单元格内容重叠可能对你有帮助。现在如果你遇到同样的问题,请毫不犹豫地敲我。

关于ios - UITableCellView.contentView 中的标签在使用自动调整大小时显示两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8566158/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com