Ios 如何实现数据表
我想实现数据表来显示用户的历史记录。我想实现这样的设计: 但是我不知道怎么做…有人能帮我吗 编辑:Ios 如何实现数据表,ios,iphone,uitableview,uicollectionview,Ios,Iphone,Uitableview,Uicollectionview,我想实现数据表来显示用户的历史记录。我想实现这样的设计: 但是我不知道怎么做…有人能帮我吗 编辑: 最好尝试使用自定义tableview单元格来显示文本,使用UIView来显示行。在我的应用程序中,我也这样做了。在特定位置添加水平线,并在该位置添加标签,结果如下所示 创建一个表视图,然后在cellforrowatinexpath方法中添加此代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPa
最好尝试使用自定义tableview单元格来显示文本,使用UIView来显示行。在我的应用程序中,我也这样做了。在特定位置添加水平线,并在该位置添加标签,结果如下所示 创建一个表视图,然后在
cellforrowatinexpath
方法中添加此代码
- (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;
}
我只为两个标签和两个水平视图创建了它,但您可以创建任意数量的标签
是的,不要忘记将此代码放置在didSelectRowAtIndexPath
中,否则当用户单击单元格时,水平视图将消失
- (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];
}
方法是使用自定义表格单元格,通过向单元格添加标签来实现此目的???是的,创建自定义单元格,添加标签和背景,使其看起来像表格,但两行之间会有空间…好的,让我试试,然后我会评论…如何使用UIView进行线条?通过XIB根据您的要求存在框架。它的bcoz您的文本较大,标签的大小较小。可以增大标签的大小,也可以减小字体的大小label@vivek我已经给出了这个问题的答案。如果你需要更多的帮助而不是问另一个问题。如果这个答案有助于你解决这个问题,那就接受它吧。是的,但我仍然没有得到确切的观点,这就是为什么…我会接受你的答案,只是因为我使用了你的代码…我想你得到了。。