gpt4 book ai didi

ios - 如何实现数据表

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

我想实现数据表来显示用户的历史记录。我想像这样实现该设计:

enter image description here

但是我不知道该怎么做...谁能帮帮我

编辑: enter image description here

最佳答案

在具体位置加上横线,在该位置加上标签,就变成这样了。

创建一个 TableView ,然后在 cellForRowAtIndexPath 方法中添加此代码..

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

NSString *SimpleTableIdentifier;
UITableViewCell * cell;

SimpleTableIdentifier = @"SimpleTableIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier: nil];

if(cell == nil) {

cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier];


UILabel * numLbl = [[UILabel alloc] initWithFrame:CGRectMake(0,5,33,30)];
numLbl.text = @"1";
[numLbl setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
numLbl.backgroundColor = [UIColor clearColor];
[cell addSubview:numLbl];

UILabel * nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(30,5,50,30)];
nameLbl.text = @"john%Lakeview";
[nameLbl setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
nameLbl.backgroundColor = [UIColor clearColor];
[cell addSubview:nameLbl];


//create a hoizontal separator in cell to display it like column
UIView* hSeparatorview1 = [[UIView alloc] initWithFrame:CGRectMake(25, 0, 1, 30)];
hSeparatorview1.backgroundColor = [UIColor blackColor];
hSeparatorview1.tag = 1;
[cell addSubview:hSeparatorview1];

UIView* hSeparatorview2 = [[UIView alloc] initWithFrame:CGRectMake(85, 0, 1, 30)];
hSeparatorview2.backgroundColor = [UIColor blackColor];
hSeparatorview2.tag = 2;
[cell addSubview:hSeparatorview2];
}

return cell;
}

//this method is used to set the hight of the tableview cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 30;
}

我只为两个标签和两个水平 View 创建了它,但您可以根据需要创建任意多个。

是的,请忘记将这段代码放在 didSelectRowAtIndexPath 中,否则当用户单击该单元格时,水平 View 将消失。

- (void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//get the cell which is selected
UITableViewCell *selectedCell = [atableView cellForRowAtIndexPath:indexPath];

//set cell horizontal saparator view color of selected cell bcoz when cell selected all view color is gone
UIView *hSeparatorview1=[selectedCell viewWithTag:1];
hSeparatorview1.backgroundColor = [UIColor blackColor];

UIView *hSeparatorview2=[selectedCell viewWithTag:2];
hSeparatorview2.backgroundColor = [UIColor blackColor];

}

关于ios - 如何实现数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779979/

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