gpt4 book ai didi

iphone - 如何在单行中管理多个标签但没有。表格 View 中的单元格取决于 iPhone SDK 中的数组。

转载 作者:行者123 更新时间:2023-11-28 17:45:43 26 4
gpt4 key购买 nike

我想像这样显示输出:

为此使用了两个部分。第一个用于标题,第二个用于显示数据,但在日期列中日期是动态的,因为它取决于解析数据,这意味着没有行取决于该数组。

那么谁能建议我,我怎样才能将多个标签放在一行中,因为下面是我的代码:在 CellForRowAtIndexPath ()

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

NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];

MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)

{
cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}


for (UIView * view in cell.contentView.subviews)
{
[view removeFromSuperview];

}

if (indexPath.section==0)
{
[cell addColumn:130];

label =[[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 64.0, 45)] autorelease];

//label.tag = LABEL_TAG;
label.font = [UIFont boldSystemFontOfSize:12];
label.text = @"Date";//[NSString stringWithFormat:@"%d", indexPath.row];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.backgroundColor=[UIColor brownColor];
label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label];


//[cell addColumn:200];
label1 =[[UILabel alloc] initWithFrame:CGRectMake(66, 0, 64.0, 45)] ;


//label1.tag = VALUE_TAG;
label1.font = [UIFont boldSystemFontOfSize:12];
// add some silly value
//label.text = [NSString stringWithFormat:@"%d", indexPath.row * 4];
label1.text = @"Gold";
label1.textAlignment = UITextAlignmentCenter;
label1.backgroundColor=[UIColor brownColor];
[cell.contentView addSubview:label1];




label2 =[[UILabel alloc] initWithFrame:CGRectMake(132.0, 0, 64, 45)] ;
//[cell addColumn:260];
label2.font = [UIFont boldSystemFontOfSize:12];
label2.text = @"Silver";
label2.textAlignment = UITextAlignmentCenter;
label2.backgroundColor=[UIColor brownColor];
[cell.contentView addSubview:label2];




label3 =[[UILabel alloc] initWithFrame:CGRectMake(198.0, 0, 62, 45)] ;
// [cell addColumn:350];
label3.font = [UIFont boldSystemFontOfSize:12];
label3.text =@"Bronze";
label3.textAlignment = UITextAlignmentCenter;
label3.backgroundColor=[UIColor brownColor];
[cell.contentView addSubview:label3];



label4 =[[UILabel alloc] initWithFrame:CGRectMake(262.0, 0, 61, 45)] ;
// [cell addColumn:350];
label4.font = [UIFont boldSystemFontOfSize:12];
label4.text =@"Avg Conf";
label4.textAlignment = UITextAlignmentCenter;
label4.backgroundColor=[UIColor brownColor];
[cell.contentView addSubview:label4];



}

else
{label5 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 64.0, 150)];
label5.font = [UIFont boldSystemFontOfSize:12];
label5.numberOfLines=4;
label5.text = [arr objectAtIndex:indexPath.row];
label5.textAlignment = UITextAlignmentLeft;
label5.textColor = [UIColor blackColor];
label5.backgroundColor=[UIColor grayColor];
[cell.contentView addSubview:label5];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

enter image description here
并且输出将根据第二张图片出现] 1

OutPut Screen According to code in CellForRowAtIndex()

最佳答案

执行此操作的最佳方法是创建 CustomTableViewCell。在 nib 文件中,可以轻松绘制所需的输出单元格。(超过 1 个标签,添加图像等)。

From here you can take the sample.

更多关于您的示例,创建两个自定义单元格,1 个用于标题,1 个用于显示所有数据。你的数据是 NSArray 的 NSArray。

关于iphone - 如何在单行中管理多个标签但没有。表格 View 中的单元格取决于 iPhone SDK 中的数组。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6120780/

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