gpt4 book ai didi

ios - 如何修改 tableView 单元格内 UIView 的大小?

转载 作者:行者123 更新时间:2023-11-28 22:13:04 25 4
gpt4 key购买 nike

我希望我的单元格有一个具有特定颜色的 UIView(用作包含颜色的简单栏),用于 TableView 中的 8 个不同行。问题是在方法 cellForRowAtIndexPath 中,我所做的更改没有显示在模拟器中。我只想使条形变量的宽度。所以这是我的代码:

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

static NSString *CellIdentifier = @"cellR";
ResumenCelda *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...

//dictSR is a dictionary where I store some data

NSString *key = [self.dictSR allKeys][indexPath.row];

NSString *sum = self.dictSR[key];

cell.categoria.text = key;
cell.montoTotal.text = sum;

//the function "calcularBarra" is implemented down below

float w = [self calcularBarra:[sum floatValue]];
NSLog(@"VALOR BARRA : %f",w);

[cell.barra setFrame:CGRectMake(129.0f, 25.0f, w, 50.0f)]; // <--- This line doesn't work!
[cell.barra setBackgroundColor:[UIColor grayColor]];
//[cell.contentView addSubview:cell.barra]; Could I omit this line of code if I already had a UIView in my Storyboard tied to "cell.barra" ?

return cell;
}

-(int)calcularBarra:(float)a

{
int widthB = (100*a)/max; //max is declared in myViewController.h as @property float max;
return widthB;
}

在我的 viewDidLoad 方法中,我计算最大值:

- (void)viewDidLoad
{
[super viewDidLoad];

for (int i=0; i<8; i++) {
NSString *key = [self.dictSR allKeys][i];
float b=[dictSR[key] floatValue];
if( b > max )
{
max=b;
}
}
NSLog(@"EL MAXIMO ES %f",max);

// Do any additional setup after loading the view.
}

我还尝试使用 UIButton,而不是使用 UIView。希望你能帮我。谢谢。

最佳答案

它可能是自动布局,检查它是否在您的单元格上被禁用。

enter image description here

关于ios - 如何修改 tableView 单元格内 UIView 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22416669/

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