如何实现DataSheet [英] How to Implement DataSheet

查看:54
本文介绍了如何实现DataSheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现数据表以显示用户的历史记录.我想实现这种设计:

I want to implement data sheet to display history of user. I want to implement that design like this:

但是我不知道该怎么做...任何人都可以帮助我

But I dont know how to do that...Can anyone please help me

推荐答案

在特定位置添加水平线,并在该位置添加标签,看起来像这样.

Add the horizontal line at the specific position and the label at the position and it will look like this.

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

Create a tableview and than in cellForRowAtIndexPath method add this code..

- (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;
}

我仅为两个标签和两个水平视图创建了它,但是您可以创建任意多个.

I have created it for only two label and two horizontal view but you can create as many as you like.

是的,点忘记了将此代码放在 didSelectRowAtIndexPath 中,否则当用户单击单元格时,水平视图将消失.

And yes dot forget to place this code in didSelectRowAtIndexPath otherwise horizontal view will disappear when user click the cell.

- (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];

}

这篇关于如何实现DataSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆