gpt4 book ai didi

iphone - 更改单元格中 detailtextlabel 的位置?

转载 作者:可可西里 更新时间:2023-11-01 03:49:49 25 4
gpt4 key购买 nike

我有一个 Iphone 应用程序,我在其中组合两个数组并显示在同一个表中。这里的问题是我无法更改单元格中详细文本标签的位置。这是我的代码片段 `

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell_with_arrow.png"]];
[cell setBackgroundView:img];
[img release];
}
if(newssarray==nil||[newssarray count]==0)
{
}
else
{
NSDictionary *dicttable=[newssarray objectAtIndex:indexPath.row];
head=[dicttable objectForKey:@"news"];
head1=[dicttable objectForKey:@"name"];
NSString *sub=[dicttable objectForKey:@"created"];

NSLog (@"%@",head);

[[cell viewWithTag:12] removeFromSuperview];
[[cell viewWithTag:13] removeFromSuperview];
[[cell viewWithTag:14] removeFromSuperview];

UIButton *shopLabel=[self buttonWithText:head andFrame:CGRectMake(49, 12, 250,5)] ;
shopLabel.tag=12;
//shopLabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
[shopLabel addTarget:self action:@selector(openRestaurantsList) forControlEvents:UIControlEventTouchUpInside];

UIButton *shopLabel1=[self buttonWithText:head1 andFrame:CGRectMake(49, 12, 250,5)] ;
shopLabel1.tag=14;
//shopLabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
[shopLabel1 addTarget:self action:@selector(openRestaurantsList) forControlEvents:UIControlEventTouchUpInside];
cell.detailTextLabel.frame = CGRectMake(49, 30, 150,5);
if(indexPath.row < [newsseperatearray count])
{
UIImage *cellImage = [UIImage imageNamed:@"news.png"];
cell.imageView.image = cellImage;
//NSStringEncoding encoding=NSASCIIStringEncoding;
cell.imageView.frame=CGRectMake(0,0,48,48);
cell.imageView.bounds=CGRectMake(0,0,48,48);
[cell.imageView setClipsToBounds:NO];
NSLog(@"%@",sub);
cell.detailTextLabel.text = sub;
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
else
{
UIImage *cellImage = [UIImage imageNamed:@"menu_icon.png"];
cell.imageView.image = cellImage;
//NSStringEncoding encoding=NSASCIIStringEncoding;
cell.imageView.frame=CGRectMake(0,0,48,48);
cell.imageView.bounds=CGRectMake(0,0,48,48);
[cell.imageView setClipsToBounds:NO];
}
[cell addSubview:shopLabel];
[cell addSubview:shopLabel1];
// [cell addSubview:shopLabel2];
}
return cell;
}

`任何人都可以帮我实现这个目标吗?

最佳答案

创建一个 UITableViewCell 子类,将该单元格样式保留为 UITableViewCellStyleSubtitle,并覆盖该子类中的 layoutSubviews。然后您可以更改 detailTextLabel 的框架(只需确保在您的方法中调用 layoutSubviews 的 super 实现)。

关于iphone - 更改单元格中 detailtextlabel 的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11407434/

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